S
sean
I'm trying to create "rubber-band" rectangles by overriding the
OnPaint method to place rectangles on top of all graphic controls, but
when I call Me.Invalidate() (when the user moves the mouse), OnPaint
is not getting called... Here is the relevent code:
I'm trying to create a "rubber band" rectangle effect on my form.
Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e
As
System.Windows.Forms.MouseEventArgs) Handles GraphicsPB.MouseMove
If LeftMouseButtonDown Then
DragEndPoint = New Point(e.X, e.Y)
Me.Invalidate()
End If
End Sub
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e)
If Math.Abs(DragStartPoint.X - DragEndPoint.X) > 1 And
Math.Abs(DragStartPoint.Y - DragEndPoint.Y) > 1 And
LeftMouseButtonDown Then
Dim XLoc As Integer = Math.Min(DragStartPoint.X +
GraphicsPB.Location.X, DragEndPoint.X + GraphicsPB.Location.X)
Dim YLoc As Integer = Math.Min(DragStartPoint.Y +
GraphicsPB.Location.Y, DragEndPoint.Y + GraphicsPB.Location.Y)
e.Graphics.DrawRectangle(Pens.Red, XLoc, YLoc,
CInt(Math.Abs(DragStartPoint.X - DragEndPoint.X)),
CInt(Math.Abs(DragStartPoint.Y - DragEndPoint.Y)))
End If
End Sub
The OnPaint method is not getting called when Me.Invalidate is
called!!!! I tried calling Me.Refresh() to no avail also. I know this
because I put an if statement inside the OnPaint method and put a
breakpoint there... What gives??
OnPaint method to place rectangles on top of all graphic controls, but
when I call Me.Invalidate() (when the user moves the mouse), OnPaint
is not getting called... Here is the relevent code:
I'm trying to create a "rubber band" rectangle effect on my form.
Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e
As
System.Windows.Forms.MouseEventArgs) Handles GraphicsPB.MouseMove
If LeftMouseButtonDown Then
DragEndPoint = New Point(e.X, e.Y)
Me.Invalidate()
End If
End Sub
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e)
If Math.Abs(DragStartPoint.X - DragEndPoint.X) > 1 And
Math.Abs(DragStartPoint.Y - DragEndPoint.Y) > 1 And
LeftMouseButtonDown Then
Dim XLoc As Integer = Math.Min(DragStartPoint.X +
GraphicsPB.Location.X, DragEndPoint.X + GraphicsPB.Location.X)
Dim YLoc As Integer = Math.Min(DragStartPoint.Y +
GraphicsPB.Location.Y, DragEndPoint.Y + GraphicsPB.Location.Y)
e.Graphics.DrawRectangle(Pens.Red, XLoc, YLoc,
CInt(Math.Abs(DragStartPoint.X - DragEndPoint.X)),
CInt(Math.Abs(DragStartPoint.Y - DragEndPoint.Y)))
End If
End Sub
The OnPaint method is not getting called when Me.Invalidate is
called!!!! I tried calling Me.Refresh() to no avail also. I know this
because I put an if statement inside the OnPaint method and put a
breakpoint there... What gives??