HighTechTalks DotNet Forums  

Custom Control Drawing

VB.net Controls microsoft.public.dotnet.languages.vb.controls


Discuss Custom Control Drawing in the VB.net Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Joel Merk
 
Posts: n/a

Default 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!


Reply With Quote
  #2  
Old   
Brad
 
Posts: n/a

Default 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.

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.