繁体   English   中英

如何防止“抽绳”被去除?

[英]How to prevent “drawstring” from being removed?

    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事件结束。 一旦检测到mouseup,我就需要单击图像中的一个点,它假设在图像本身上绘制字符串(在图像上绘制“ 1”)。 对于第一个束带事件,结果很好。 但是,一旦触发mousedown事件,它将删除先前的drawstring(“ 1”)。 有人可以帮助我如何防止删除“上一个”抽绳吗? 谢谢大家!

不要直接在油漆盒中画画。 改为绘制PaintBox的图像。 并在MouseMove事件结束时执行此操作,然后再调用Side_pictureBox.Invalidate();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM