P
padawan
I have a winforms control that draws a rectangle for a boarder and positions
some graphical elements around the control to create the boarder effect I
desired. In the control I have overriden the onpaint event and added the
code to draw my rectangle and position my graphic items:
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.Clear(Color.FromArgb(255, 255, 255))
MyBase.OnPaint(e)
Dim g As Graphics = pb1.CreateGraphics
pb1.CreateGraphics.Clear(Color.FromArgb(255, 255, 255))
Dim myPen As System.Drawing.Pen = New System.Drawing.Pen(Color.FromArgb(187,
191, 115))
g.DrawRectangle(myPen, New Rectangle(0, 0, pb1.Width - 1, pb1.Height - 1))
pb1.Width = (Me.Width - 34)
pb1.Height = (Me.Height - 29)
tr.Left = (Me.Width - 32)
br.Left = (Me.Width - 32)
br.Top = (Me.Height - 24)
bl.Top = (Me.Height - 24)
End Sub
Also I have added this line to the Public sub new call of the control:
SetStyle(ControlStyles.ResizeRedraw, True)
As you can see the rectangle is being drawn on a panel control called "pb1".
When I drag this control onto a Windows form in Visual Studio the rectangle
is drawn and behaves as it should when resized etc. However if I switch to
antother tab and switch back the rectangle disapears, this is also the case
when the solution is compiled the form initializes with no rectangle. Can
somebody please help me or point me in the right direction.
some graphical elements around the control to create the boarder effect I
desired. In the control I have overriden the onpaint event and added the
code to draw my rectangle and position my graphic items:
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.Clear(Color.FromArgb(255, 255, 255))
MyBase.OnPaint(e)
Dim g As Graphics = pb1.CreateGraphics
pb1.CreateGraphics.Clear(Color.FromArgb(255, 255, 255))
Dim myPen As System.Drawing.Pen = New System.Drawing.Pen(Color.FromArgb(187,
191, 115))
g.DrawRectangle(myPen, New Rectangle(0, 0, pb1.Width - 1, pb1.Height - 1))
pb1.Width = (Me.Width - 34)
pb1.Height = (Me.Height - 29)
tr.Left = (Me.Width - 32)
br.Left = (Me.Width - 32)
br.Top = (Me.Height - 24)
bl.Top = (Me.Height - 24)
End Sub
Also I have added this line to the Public sub new call of the control:
SetStyle(ControlStyles.ResizeRedraw, True)
As you can see the rectangle is being drawn on a panel control called "pb1".
When I drag this control onto a Windows form in Visual Studio the rectangle
is drawn and behaves as it should when resized etc. However if I switch to
antother tab and switch back the rectangle disapears, this is also the case
when the solution is compiled the form initializes with no rectangle. Can
somebody please help me or point me in the right direction.