473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Ownderdraw vs Creating Control from scratch?

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
2 2140
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Zeke | last post by:
I'm using the following code to create word document but the problem is if you go to task manager you'll see a WINWORD.EXE process is running but not the application, here is the code: ...
0
by: Patrick Blackman | last post by:
Hi have created a richtextbox from scratch using the following code: public class TextPad:Control { public TextPad(){} //RichTextBox overrides protected override CreateParams CreateParams {...
4
by: Alvo von Cossel I | last post by:
hi, i have been asked to make a good-looking app for a friend. i have an options form with a big tabstrip in it. 1. how can i customize it e.g. change from the standard system style...
2
by: Dan Nash | last post by:
Hi peeps I need to use a Gantt charting display in my project. Unfortunately, the client has no spare cash for such frivolities as buying controls, so I'm going to have to write something. So I...
0
by: Steve | last post by:
When coding in vbscript asp, I did everything from scratch and could control the way that for example my data tables looked and could be edited. I for example could allow the user to delete...
1
by: Franck | last post by:
Hello, I need to implement the following features: I need to create a document on whatever format word, pdf … A simple one; few field taken from a DB. This document should be printed on a client...
15
by: guy | last post by:
Where can i find an example of authoring a combobox control FROM SCRATCH in vb.net ??
6
by: André Nogueira | last post by:
Hi there. First of all, sorry for the double post, but I was not sure about which was the most correct group for this question... I am trying to create my own control that will be alot like the...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.