Objects derived from Control are easy to create. To paint the control,
override the OnPaint method and paint on the Graphics object provided in the
PaintEventArgs parameter. You may also wish to override the
OnPaintBackground to prevent the default clearing of the graphics or to add
some custom background.
This simple control draws a circle shape..
Public Class CircleControl
Inherits Control
Public Overrides Sub OnPaint(ByVal e as PaintEventArgs)
Dim b As New SolidBrush(Me.ForeColor)
e.Graphics.DrawEllipse(b,0,0,Me.ClientSize.Width, Me.ClientSize.Height)
b.Dispose()
End Sub
End Class
Existing controls such as the combobox and textbox are based on the old
Win32 controls and are often more difficult to customize. Some controls do
provide owner-draw options which you can take advantage of. The mechanism
for OwnerDraw is more or less the same as that for MenuItem inasmuch as
there is generally a MeasureItem event in which you declare the size of the
object you're drawing and a DrawItem event where you actually paint the
bits. For a custom control, OnPaint is all you really need.
As for tutorials, this one on DevCity might be useful to you but I think
it's on the slowest server in the known universe.
http://www.devcity.net/net/article.a..._customcontrol
--
Bob Powell [MVP]
Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed:
http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tipstricks.xml
Bob's Blog:
http://bobpowelldotnet.blogspot.com/atom.xml
"Try Guy" <no****@no.no> wrote in message
news:uJ*************@TK2MSFTNGP12.phx.gbl...
I'm not sure if I really understand this whole ownderdraw thing...
i want to create my own Windows Forms control (NOT USERCONTROL)...is it
ownerdrawing I should start learning or something else?
And where do you learn this stuff? I've been looking for tutorials but all
are for C # or how to use prebuild stuff... I wanna learn how to really do
it.
If I learn to use Ownerdraw on Menuitems... can I then also use the same
knowledge for modifying a combobox or is it very different from control to
control?
/Try Guy