C# 用户定义的绘图不可见
我有一个Windows窗体应用程序,其中有一个GroupBox,一个PictureBox作为背景图像,还有几个PowerPack中的可单击椭圆形 现在我需要一些椭圆形的标签,所以我在我的GroupBox上放置了一个EventHandler,在每次重新绘制时,应该绘制以下内容C# 用户定义的绘图不可见,c#,winforms,gdi+,C#,Winforms,Gdi+,我有一个Windows窗体应用程序,其中有一个GroupBox,一个PictureBox作为背景图像,还有几个PowerPack中的可单击椭圆形 现在我需要一些椭圆形的标签,所以我在我的GroupBox上放置了一个EventHandler,在每次重新绘制时,应该绘制以下内容 this.groupBoxTest.Paint += new System.Windows.Forms.PaintEventHandler(this.groupBoxVirtualView_Paint); private
this.groupBoxTest.Paint += new System.Windows.Forms.PaintEventHandler(this.groupBoxVirtualView_Paint);
private void groupBoxVirtualView_Paint(object sender, PaintEventArgs e)
{
Graphics g = groupBoxVirtualView.CreateGraphics();//e.Graphics;
g.DrawString("01", new Font("Arial", 12), new SolidBrush(Color.Black), 240, 115);
}
但是字符串01
从未被绘制;我所看到的只是处于同一位置的椭圆形——禁用它们进行测试也不行
我的绳子怎么了
是否有其他方法标记我的PoweredOval?您必须使用
groupBoxVirtualView.Invalidate()
重新绘制组框 绘制事件应使用发件人提供的图形对象:
private void groupBoxVirtualView_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("01", new Font("Arial", 12), new SolidBrush(Color.Black), 240, 115);
}
此外,如果GroupBox中有PictureBox,则该控件将不会显示任何要通过控件显示的GroupBox绘画。它将隐藏它。如果一个PictureBox在GroupBox中,PictureBox不会隐藏您在GroupBox中绘制的任何东西吗?顺便说一句,不要使用CreateGraphics,使用e.Graphics。我在代码中是这样的,我复制错了:new System.Windows.Forms.PaintEventHandler(this.groupBoxVirtualView_Paint)@JulianSchaefer我只能看你发布的内容。尝试链接表单的屏幕截图。那么图片盒呢?GroupBox里面有吗?