I have a panel that I'm trying to draw a blue border around. I'm using the following code to draw the blue rectangle. The problem is when I add a control to the panel and sets its dockstate to fill it hides the blue border.
With my example I derrive the graphics object from the control. And as a result the control hides the blue rectangle because its underneath the control.
I don’t want to draw a rectangle on the panels container as the panel fills the container.
I don’t want to draw a rectangle on the control. For other reasons…
The graphics object is derived from object where the graphic is to be drawn.
Questions:
Private Sub DrawRectanle
Dim myGraphics As Graphics
Dim myRectangle As Rectangle
Dim myPen As New Pen(Color.Red)
'return the current form as a drawing surface
myGraphics = Panel1.CreateGraphics()
myRectangle = New Rectangle(Panel1.Location.X, Panel1.Location.Y, Panel1.Size.Width, Panel1.Size.Height)
'draw rectangle from pen and rectangle objects
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
End Sub