By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,481 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,481 IT Pros & Developers. It's quick & easy.

Ownderdraw vs Creating Control from scratch?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Nov 20 '05 #2

P: n/a
HeY!

Thank you! That looks like what I'm loking for and thanx for straiting
things out for me... been playing around with the DrawItem even now in a
listbox (while I was waiting for an answer) and it gives me a lot more ideas
on what I can actually do.. and off course raises many many questions:)

Will read the tutorial now:)

Thanx again!

Best Regards
/Try Guy
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> skrev i meddelandet
news:OE**************@TK2MSFTNGP11.phx.gbl...
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


Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.