Custom Control Drawing - 03-18-2008 , 02:42 AM
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.
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
border.Width = border.Width - 3
border.Height = border.Height - 3
e.Graphics.DrawRectangle(New Pen(Color.LightGreen, 3), border)
Public Sub New()
' This call is required by the Windows Form Designer.
' Add any initialization after the InitializeComponent() call.
<Global.Microsoft.VisualBasic.CompilerServices.Des ignerGenerated()> _
Partial Class Marker
'Control overrides dispose to clean up the component list.
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
'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.
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
The same thing happens when inheriting from usercontrol and drawing my
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.
RE: Custom Control Drawing - 04-24-2008 , 08:20 PM
Try the Invalidate routine. I had this problem when trying to draw a custom
border around my windows form. Once I added the Me.Invalidate routine to the
form resizing event it solved my problem.
|Thread Tools||Search this Thread|