[Inputbox block system.drawing

问题描述 投票:0回答:1

我正在尝试在表单上编码此功能:用户单击表单,输入框要求用户输入名称,然后在用户单击的表单上的位置绘制一个圆圈。我现在面临的一个问题是,现在在输入框显示的地方绘制了圆圈。实际上,我有一个功能可以重画表单上的每个圆圈,但是仍然无法正常工作。这是我的代码:

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.

    }
c# winforms inputbox
1个回答
0
投票

仅画图还不够。每次重新绘制表格时,都需要重新绘制一次。第一步是覆盖OnPaint

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    // paint your circles here, when they need to be persisted 
    // e.Graphics.DrawRectangle(redPen, r);
}

显然,您需要跟踪需要绘制的内容,以及何时不再需要绘制的内容,但这应该可以帮助您入门。>

© www.soinside.com 2019 - 2024. All rights reserved.