Create an owner drawn ListBox

G

Gladys

Hi everybody, i have a problem creating a owner drawn ListBox.

I need a ListBox that accepts graphic icons (.ico) files between the text
(e.g. some text [myIcon.ico] more text and then another icon [myIcon.ico]
and some text )
So i I am assuming that this is only possible creating a owner drawn
ListBox.
I'm a beginner, so an simple example would be nice.

Thanks in advance,

Gladys
 
G

Gladys

Toidy,

This example (I had already found this example) is still very
unclear/complicated to me.

My project has one listbox, three textboxes, a button and an imagelist with
one icon file.
The only thing i want to do (difficult enough for me) is add the text from
textbox1, textbox2 and textbox3 to the listbox, all text parts separted by
an icon from the imagelist.
I tried to adapt this example for my purpose, but it always failed.
I would appreciate a simpler example if possible.

http://www.devx.com/dotnet/Article/8014/0/page/2
This example seems to be VB.NET and not C#. (I had already found this
example also)

Thanks in advance,

Gladys
 
J

Jeff Johnson

Hi everybody, i have a problem creating a owner drawn ListBox.

I need a ListBox that accepts graphic icons (.ico) files between the text
(e.g. some text [myIcon.ico] more text and then another icon
[myIcon.ico] and some text )
So i I am assuming that this is only possible creating a owner drawn
ListBox.
I'm a beginner, so an simple example would be nice.

My first question is "Do you have enough experience with the Graphics object
to draw what you want on, say, a PictureBox?" Because I'd say that's a
prerequisite for using OwnerDraw.
 
P

Peter Duniho

Jeff said:
My first question is "Do you have enough experience with the Graphics object
to draw what you want on, say, a PictureBox?" Because I'd say that's a
prerequisite for using OwnerDraw.

Agreed. With the minor nit to pick, that using a PictureBox as the base
implementation just for an arbitrary custom control is usually not
advantageous. Most custom controls should just inherit Control.

Pete
 
J

Jeff Johnson

Agreed. With the minor nit to pick, that using a PictureBox as the base
implementation just for an arbitrary custom control is usually not
advantageous. Most custom controls should just inherit Control.

Oh, I wasn't suggesting using the PictureBox in that manner. I was just
wondering if the OP knew how to draw at all, and the PictureBox seemed like
the easiest thing to draw on. I guess you could just draw right on a Form,
though.
 
G

Gladys

Agreed. With the minor nit to pick, that using a PictureBox as the base
implementation just for an arbitrary custom control is usually not
advantageous. Most custom controls should just inherit Control.

I'd like to use the listbox control and not creating a custom control.


Gladys
 
J

Jeff Johnson

I'd like to use the listbox control and not creating a custom control.

That's not the issue. The real issue is whether or not you're familiar with
drawing text and graphics at all. Are you?
 
J

Jeff Johnson

Nope :-((

Okay. What I'm getting at here is that you're trying to bite off a really
large chunk. I recommend taking it in smaller pieces. Get examples of simply
using graphics, and then look into the samples of doing OwnerDraw. The
second part won't be that hard; you'll just come to realize that when doing
OwnerDraw you get a "sandbox" area in which you're able to draw as opposed
to having an entire window (which is ultimately just a bigger sandbox) on
which to draw.
 
P

Peter Duniho

Jeff said:
Oh, I wasn't suggesting using the PictureBox in that manner. I was just
wondering if the OP knew how to draw at all, and the PictureBox seemed like
the easiest thing to draw on.

What makes the PictureBox any easier to draw on than anything else?
I guess you could just draw right on a Form, though.

You don't even need a Form. You can just create a Control sub-class of
your own. Or you can drop a Panel instance into the Form and subscribe
to its Paint event to draw into that (the Panel has the nice quality
that it's very simple, has no visual elements of its own, but is still a
full-fledged control that can be manipulated in the Designer…in other
words, it's pretty much the simplest control available, short of just
writing one's own Control sub-class).

Pete
 
J

Jeff Johnson

What makes the PictureBox any easier to draw on than anything else?


You don't even need a Form. You can just create a Control sub-class of
your own. Or you can drop a Panel instance into the Form and subscribe to
its Paint event to draw into that (the Panel has the nice quality that
it's very simple, has no visual elements of its own, but is still a
full-fledged control that can be manipulated in the Designer…in other
words, it's pretty much the simplest control available, short of just
writing one's own Control sub-class).

Apparently I haven't been clear. I'm talking about for testing and learning
purposes ONLY. I'm not suggestion any implementation. And for learning, it
seems to me far easier to just create a new Windows Forms project, slap a
PictureBox on it, and draw. Or just draw on the form. Your suggestion about
creating your own custom control seems like it's more for a final product
than simply playing with the Graphics object.
 
V

vanderghast

You don't need a special control in order to make your own painting "per
item" with a list box since setting the DrawMode property to OwnerDrawFixe
of OwnerDrawVariable would allow listbox_DrawItem event to fire, with an
appropriate graphical environment.
http://www.amazon.com/Windows-Forms...=sr_1_1?ie=UTF8&s=books&qid=1270564182&sr=1-1,
pages 362-365 supply two examples (one with fixed height, one with variable
height, per item (listbox_MeasureItem event is then involved too, in this
last case)).


Vanderghast, Access MVP
 
P

Peter Duniho

Jeff said:
Apparently I haven't been clear. I'm talking about for testing and learning
purposes ONLY. I'm not suggestion any implementation. And for learning, it
seems to me far easier to just create a new Windows Forms project, slap a
PictureBox on it, and draw. Or just draw on the form. Your suggestion about
creating your own custom control seems like it's more for a final product
than simply playing with the Graphics object.

Nevertheless, that doesn't answer my question. Even for "testing and
learning purposes", what makes the PictureBox class easier to use or
otherwise a superior choice over, for example, the Panel class?

If you've got an image to display and don't want to use DrawImage()
yourself, then sure…PictureBox seems like a fine choice. But for simply
drawing, it seems like overkill to me. Why do you feel it's better than
other choices available?

Pete
 
G

Gladys

You don't need a special control in order to make your own painting "per
item" with a list box since setting the DrawMode property to OwnerDrawFixe
of OwnerDrawVariable would allow listbox_DrawItem event to fire, with an
appropriate graphical environment.
http://www.amazon.com/Windows-Forms...=sr_1_1?ie=UTF8&s=books&qid=1270564182&sr=1-1,
pages 362-365 supply two examples (one with fixed height, one with
variable height, per item (listbox_MeasureItem event is then involved too,
in this last case)).

Thanks !
I have found a copy!

Gladys
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top