簡體   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