简体   繁体   中英

Displaying a PictureBox inside a GroupBox

I have a Picturebox, which I paint on the click of a button:

private void btnDisplay_Click(object sender, EventArgs e)
{
    MyDisplay.Refresh();
}
private void PaintDisplay(object sender, System.Windows.Forms.PaintEventArgs e)
{
    Graphics graphics = e.Graphics;
    DrawDisplay(graphics);
}

This works fine. But when I copy the Picturebox into a groupbox, the PaintDisplay() fails to trigger. Is there anything I will need to do to my groupbox, in order to get the display to show again?

"Thanks. That did the trick."

If you literally copied the PictureBox in the design of the Form then you have to wire up the new PictureBox's Paint() event so it points to PaintDisplay() as well. If you moved the PictureBox into the GroupBox by using cut followed by paste, then this will detach the handler. Re-wire it by selecting the PictureBox, clicking the "Lightning Bolt" icon in the Properties Pane, and changing the DropDown to the right of Paint() to "PaintDisplay"

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