Custom Control Drawing -
03-18-2008
, 02:42 AM
Hello
I am creating a custom (user control) in vb.net. I have figured out how to
draw the control how I want, and this is not my problem. My problem is that I
would like to be able to *drag* my control around the form, using mouse
events, and changing the control.location property. Everything works fine,
until the instance being dragged passes over another stationary instance of
the control. The stationary control gets *streaks* or *residue* left by the
moving control's OnPaint sub.
Here is an example of what happens when one control is dragged over another.
http://i29.tinypic.com/9h6o80.png
In this example, I am addind on to a label control:
Public Class Marker
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim border As Rectangle = e.ClipRectangle
border.Location = New Point(border.Location.X + 1, border.Location.Y
+ 1)
border.Width = border.Width - 3
border.Height = border.Height - 3
e.Graphics.DrawRectangle(New Pen(Color.LightGreen, 3), border)
MyBase.OnPaint(e)
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.Des ignerGenerated()> _
Partial Class Marker
Inherits System.Windows.Forms.Label
'Control overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Control Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer. Do not modify it
' using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
End Class
The same thing happens when inheriting from usercontrol and drawing my
control.
My question is, how can I stop this from happening? What do I need to add to
my control to make it behave the same way as non-custom controls? Every
default control that I have experimented with does not show this behavious
unless I add custom code to the OnPaint method.
Thanks! |