private void Side_pictureBox_Paint(object sender, PaintEventArgs e)
{
if (doubleclicked == true)
{
Side_pictureBox.Refresh();
for (int numbering_for_digram = 1; numbering_for_digram <= No_of_circle; numbering_for_digram++)
{
//MessageBox.Show(numbering_for_digram.ToString());
String drawString = numbering_for_digram.ToString();
// Create font and brush.
Font drawFont = new Font("Calibri (Body)", 20);
SolidBrush drawBrush = new SolidBrush(Color.Blue);
// Create point for upper-left corner of drawing.
//float x = 0;
//float y = 0;
doubleclicked = false;
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, lastPoint);
Side_pictureBox.Update();
//MessageBox.Show("passed graphics draw");
}
}
}
}
private void Side_pictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown == true && Edit_Variables.add_remark_now==false)//check to see if the mouse button is down
{
if (lastPoint != null)//if our last point is not null, which in this case we have assigned above
{
if (Side_pictureBox.Image == null)//if no available bitmap exists on the picturebox to draw on
{
//create a new bitmap
Bitmap bmp = new Bitmap(Side_pictureBox.Width, Side_pictureBox.Height);
Side_pictureBox.Image = bmp; //assign the picturebox.Image property to the bitmap created
}
using (Graphics g = Graphics.FromImage(Side_pictureBox.Image))
{//we need to create a Graphics object to draw on the picture box, its our main tool
//when making a Pen object, you can just give it color only or give it color and pen size
g.DrawLine(new Pen(Color.DarkRed, 2), lastPoint, e.Location);
g.SmoothingMode = SmoothingMode.AntiAlias;
//this is to give the drawing a more smoother, less sharper look
}
Side_pictureBox.Invalidate();//refreshes the picturebox
lastPoint = e.Location;//keep assigning the lastPoint to the current mouse position
}
}
Так работает весь процесс, во-первых, я буду рисовать пером на изображении. Этот процесс рисования начинается с mousedown и заканчивается событием mouseup. Как только наведен указатель мыши, я должен нажать на точку на изображении, и она предполагает рисовать строку (рисует «1» на изображении) на самом изображении. Для первого случая с кулиской получается нормально. Однако, как только я вызову событие mousedown, оно удалит предыдущую строку Drawstring («1»). Может кто-нибудь помочь, как я могу предотвратить удаление "предыдущей" кулисы? Спасибо всем большое!