The DrawToBitmap
method will capture the graphics drawn in the Paint
event and all nested controls. If one is missing it isn't nested either directly of indirectly. Here is how this probably happened:
The designer behaviour of Panels
and PictureBoxes
is different.
Panels
, like GroupBoxes
, TabPages
and a few more are container controls.
This means that any control you drag onto them with your mouse gets nested in them.
PictureBox
is not a Container, like, say a Button
or a Label
..
To nest your DataGridView
in the PictureBox
you have a choice of
- moving it there with the keyboard (!)
- nesting it in code (
yourDGV.Parent = yourPBox1;
)
Do test the success of the keyboard way by moving the PictureBox
to see if the DGV
moves with it..
Update:
If you nest the DGV
in the PictureBox
, which itself is nested in the Panel
, all will be well and the result will looks just like what you see.
However, if you nest both DGV
and PictureBox
in the Panel
and merely let them overlap, a strange bug will appear: Multiple overlapping controls are drawn in reverse, See here for a post and a link about this issue, which is documented
Controls inside containers are rendered in reverse order.
but obviously still a bug.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…