Search code examples
c#winformsinputbox

Inputbox block the system.drawing


I am trying to code this function on a form: User click on the form, a inputbox asks user to input a name, and a circle is drawn on the place in the form where the user clicks. One issue now I faces is that circle is now draw at the place where the inputbox show up. I actually have a function to repaint every circle on the form, but it still does not work. Here is my code:

private void Form1_MouseClick(object sender, MouseEventArgs e)
    {
        string ProvinceName;
        System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
        System.Drawing.Graphics formGraphics;
        formGraphics = this.CreateGraphics();

        formGraphics.FillEllipse(myBrush, new Rectangle(e.X, e.Y, 10, 10));

        ProvinceName = Microsoft.VisualBasic.Interaction.InputBox("郡名", "", "无名",100,100);

        provinces.Add(new province(ProvinceName, e.X, e.Y));

        listBox1.SelectedIndex = provinces.Count - 1;

        myBrush.Dispose();
        formGraphics.Dispose();
        PaintMap();// This is the function repaint every recorded clicked locations.

    }

Solution

  • I used Bipmap to store the paint and then use paint event to repaint the form. The problem is solved. I think when I directly use "System.Drawing, I paint on the inputbox.