首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何防止"drawstring“被移除?

如何防止"drawstring“被移除?
EN

Stack Overflow用户
提问于 2019-01-12 17:44:13
回答 1查看 60关注 0票数 0
代码语言:javascript
运行
复制
    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“)。对于第一个drawstring事件,它被证明是好的。然而,一旦我触发mousedown事件,它将删除之前的drawstring("1")。有人能帮我吗?我怎样才能防止“以前”的拉弦被移除?非常感谢大家!

EN

回答 1

Stack Overflow用户

发布于 2019-01-12 18:10:18

不要直接在颜料盒中绘制。取而代之的是绘制PaintBox的图像。在调用Side_pictureBox.Invalidate();之前,在your MouseMove事件结束时执行此操作

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54158383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档