简体   繁体   中英

User defined painting not visible

I have a Windows Forms application with a GroupBox, and a PictureBox as background image, and several clickable OvalShapes from the PowerPack.

Now I need some labels for the OvalShapes, so I put a EventHandler on my GroupBox that on every repaint, the following should be drawn

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);
}

But the string 01 never gets drawn; all I see are the oval shapes that are at the same position - disabling them for testing purpose doesn't do it either.

What's happening to my string?

Any other way to label my PoweredOval?

You have to use

groupBoxVirtualView.Invalidate();

to repaint the groupBox!

The paint event should use the graphic object from the sender:

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);
}

Also, if there is a PictureBox inside the GroupBox, that control will not show any of the GroupBox paintings to come through the control. It will hide it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM