J
Joel Whitehouse
Hey guys,
I have a quick question:
I am trying to draw a border around a control with GDI to highlight it.
Here is my simple test code added onto a new Usercontrol to make it's
border turn off and on with a user's click:
Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Private _draw as Boolean
Private _pen as System.Drawing.Pen
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Instantiate pen
_pen = New System.Drawing.Pen(System.Drawing.Color.Red, 4)
End Sub
Private Sub UserControl1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Click
'Invert the draw flag
_draw = Not _draw
'Redraw form
MyBase.Refresh()
End Sub
Protected Overreides Sub OnPaint(ByVal e as PaintEventArgs)
Dim g As Graphics = e.Graphics
If (_draw) Then
g.Clear(Me.BackColor)
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
g.DrawRectangle(_pen, MyBase.DisplayRectangle)
g.Fluch(Drawing2d.FlushIntention.Sync)
End If
End Sub
End Class
The problem? The toggling only works if I click the control and then
drag it off the viewable area of the screen, and then drag it back onto
the viewable area again. How do I force the rectangle to auto-redraw?
Thanks!
-Joel
I have a quick question:
I am trying to draw a border around a control with GDI to highlight it.
Here is my simple test code added onto a new Usercontrol to make it's
border turn off and on with a user's click:
Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Private _draw as Boolean
Private _pen as System.Drawing.Pen
Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Instantiate pen
_pen = New System.Drawing.Pen(System.Drawing.Color.Red, 4)
End Sub
Private Sub UserControl1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Click
'Invert the draw flag
_draw = Not _draw
'Redraw form
MyBase.Refresh()
End Sub
Protected Overreides Sub OnPaint(ByVal e as PaintEventArgs)
Dim g As Graphics = e.Graphics
If (_draw) Then
g.Clear(Me.BackColor)
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
g.DrawRectangle(_pen, MyBase.DisplayRectangle)
g.Fluch(Drawing2d.FlushIntention.Sync)
End If
End Sub
End Class
The problem? The toggling only works if I click the control and then
drag it off the viewable area of the screen, and then drag it back onto
the viewable area again. How do I force the rectangle to auto-redraw?
Thanks!
-Joel