I am trying to write an EventHandler for a UserControl I wrote, but for some reason the Control does not seem to have a ClipRectangle:
Private Sub paints(sender As Object, p As PaintEventArgs) Handles Me.Paint
ControlPaint.DrawBorder(p.Graphics, p.ClipRectangle, SystemColors.AppWorkspace, ButtonBorderStyle.Solid)
End Sub
When I try and add MyBase.OnPaint(p) I get a StackOverflow because for some reason this seems to trigger some endless recursion.
So why is there no Rectangle?
The outline of the UserControl is something like this:
UserControl
- TableLayout
- - TableLayout
- - - Label
- - - Label
- - TextBox
And it should be something like 250x50 pixels.
PaintEventArgs.ClipRectangle
is a rectangle that needs to be painted. If there are no controls on your usercontrol then it is the client area. But if there are other controls then it clips their area from client rectangle! Probably your child controls occupy the whole client area so there is no need for drawing thus returning (0, 0, 0, 0)
.