Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler.
What I want to draw as the item is another control. I have created a user control that I
would like to list in this listbox but I can't for the life of me figure out how to draw the
control inside ListBox...
I get as far as:
private void lbImageList_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
// Set the DrawMode property to draw fixed sized items.
lbImageList.DrawMode = DrawMode.OwnerDrawFixed;
// Draw the background
e.DrawBackground();
// Now draw my control in there... umm....
e.
}
Help! :)
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk 8 2717
If you already have a user control, there is no need to ‘draw’ it within the
listbox, instead, simply reposition the user control to the desired location
on top of the list box.
This same method is often used if someone wants to add their own buttons to
a status bar, they create a new class that inherits from the regular
StatusBar class, and also contain the desired buttons, whenever a given panel
is painted, the button’s size and location is adjusted to the corresponding
region.
"Oddball" wrote: Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler.
What I want to draw as the item is another control. I have created a user control that I would like to list in this listbox but I can't for the life of me figure out how to draw the control inside ListBox...
I get as far as:
private void lbImageList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { // Set the DrawMode property to draw fixed sized items. lbImageList.DrawMode = DrawMode.OwnerDrawFixed; // Draw the background e.DrawBackground();
// Now draw my control in there... umm.... e.
}
Help! :)
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
Great! I've done that and the controls are now displaying properly.
As a related query I now want the user to be able to click anywhere within my control
and fire the same event. Seeing as how the control is being written on top of the
ListBox I can't fire the usual ListBox events (click, drag, etc.) but my control is made up
of a number of other controls which all have their own events.
How do I get back the standard ListBox controls?! :)
I'm just never happy, am I :)
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?="
<Br**********@discussions.microsoft.com> wrote: If you already have a user control, there is no need to ‘draw’ it within the listbox, instead, simply reposition the user control to the desired location on top of the list box.
This same method is often used if someone wants to add their own buttons to a status bar, they create a new class that inherits from the regular StatusBar class, and also contain the desired buttons, whenever a given panel is painted, the button’s size and location is adjusted to the corresponding region.
"Oddball" wrote:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event
handler. What I want to draw as the item is another control. I have created a user control
that I would like to list in this listbox but I can't for the life of me figure out how to draw the control inside ListBox...
I get as far as:
private void lbImageList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { // Set the DrawMode property to draw fixed sized items. lbImageList.DrawMode = DrawMode.OwnerDrawFixed; // Draw the background e.DrawBackground();
// Now draw my control in there... umm.... e.
}
Help! :)
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
I would suggest using a usercontrol that contains all of these sub controls
you want, all of which pipe the events you care about back to the user
control.
As an example, both your custom control and listbox both respond to the
Click event, so have both events trigger the click event of the parent user
control.
"Oddball" wrote: Great! I've done that and the controls are now displaying properly.
As a related query I now want the user to be able to click anywhere within my control and fire the same event. Seeing as how the control is being written on top of the ListBox I can't fire the usual ListBox events (click, drag, etc.) but my control is made up of a number of other controls which all have their own events.
How do I get back the standard ListBox controls?! :)
I'm just never happy, am I :)
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" <Br**********@discussions.microsoft.com> wrote:
If you already have a user control, there is no need to ‘draw’ it within the listbox, instead, simply reposition the user control to the desired location on top of the list box.
This same method is often used if someone wants to add their own buttons to a status bar, they create a new class that inherits from the regular StatusBar class, and also contain the desired buttons, whenever a given panel is painted, the button’s size and location is adjusted to the corresponding region.
"Oddball" wrote:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in this listbox but I can't for the life of me figure out how to draw the control inside ListBox...
I get as far as:
private void lbImageList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { // Set the DrawMode property to draw fixed sized items. lbImageList.DrawMode = DrawMode.OwnerDrawFixed; // Draw the background e.DrawBackground();
// Now draw my control in there... umm.... e.
}
Help! :)
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
I've got a ListBox with a number of user controls which are floating on top of the
control.
The problem I have is the with this method of insterting my user controls into the listbox
I have lost the ability to use the ListBox's inbuilt events (doubleclick, drag, etc).
This wouldn't be a problem if I could fire an event if a user clicks, drags... whatever...
ANYWHERE on my control but as it is I have to add handlers for every control
contained within my user control.
Is it possible to either move the Listbox's behavior to the fore or to add a kind of
invisible panel over my control so that you get the same event fired no matter where
you click?
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
Could you give me an example of how I would do this?
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?="
<Br**********@discussions.microsoft.com> wrote: I would suggest using a usercontrol that contains all of these sub controls you want, all of which pipe the events you care about back to the user control.
As an example, both your custom control and listbox both respond to the Click event, so have both events trigger the click event of the parent user control.
"Oddball" wrote:
Great! I've done that and the controls are now displaying properly.
As a related query I now want the user to be able to click anywhere within my
control and fire the same event. Seeing as how the control is being written on top of the ListBox I can't fire the usual ListBox events (click, drag, etc.) but my control is made
up of a number of other controls which all have their own events.
How do I get back the standard ListBox controls?! :)
I'm just never happy, am I :)
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" <Br**********@discussions.microsoft.com> wrote:
>If you already have a user control, there is no need to ‘draw’ it
within the >listbox, instead, simply reposition the user control to the desired location >on top of the list box. > >This same method is often used if someone wants to add their own buttons to >a status bar, they create a new class that inherits from the regular >StatusBar class, and also contain the desired buttons, whenever a given panel >is painted, the button’s size and location is adjusted to the corresponding >region. > >"Oddball" wrote: > >> >> Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. >> >> What I want to draw as the item is another control. I have created a user control that I >> would like to list in this listbox but I can't for the life of me figure out how to draw
the >> control inside ListBox... >> >> I get as far as: >> >> private void lbImageList_DrawItem(object sender, >> System.Windows.Forms.DrawItemEventArgs e) >> { >> // Set the DrawMode property to draw fixed sized items. >> lbImageList.DrawMode = DrawMode.OwnerDrawFixed; >> // Draw the background >> e.DrawBackground(); >> >> // Now draw my control in there... umm.... >> e. >> >> } >> >> Help! :) >> >> >> ------------------------------------ >> >> Another unchecked rambeling brought to you by: >> >> Oddball >> joshua@bf#N0SP4M#wd.co.uk >>
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
For my example, I am using the MouseDown event from 3 buttons, the listbox
and the user control. Within the InitializeComponent() function I have the
following to setup my listening to the specific events within the user
control.
this.listBox1.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.MyMous eDownHandler);
this.button1.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.MyMous eDownHandler);
this.button2.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.MyMous eDownHandler);
this.button3.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.MyMous eDownHandler);
this.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.MyMous eDownHandler);
You notice that all of them call the same function, which is written as:
private void MyMouseDownHandler(object sender,
System.Windows.Forms.MouseEventArgs e)
{
this.OnMouseDown(sender, e);
}
This makes it simple to choose which events and from what controls should
trigger the events provided by the user control. One warning though, not all
controls support the same events, the Click event for instance does not exist
as part of the ListBox class, but does as part of many others.
"Oddball" wrote: Could you give me an example of how I would do this?
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" <Br**********@discussions.microsoft.com> wrote:
I would suggest using a usercontrol that contains all of these sub controls you want, all of which pipe the events you care about back to the user control.
As an example, both your custom control and listbox both respond to the Click event, so have both events trigger the click event of the parent user control.
"Oddball" wrote:
Great! I've done that and the controls are now displaying properly.
As a related query I now want the user to be able to click anywhere within my control and fire the same event. Seeing as how the control is being written on top of the ListBox I can't fire the usual ListBox events (click, drag, etc.) but my control is made up of a number of other controls which all have their own events.
How do I get back the standard ListBox controls?! :)
I'm just never happy, am I :)
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" <Br**********@discussions.microsoft.com> wrote:
>If you already have a user control, there is no need to ‘draw’ it within the >listbox, instead, simply reposition the user control to the desired location >on top of the list box. > >This same method is often used if someone wants to add their own buttons to >a status bar, they create a new class that inherits from the regular >StatusBar class, and also contain the desired buttons, whenever a given panel >is painted, the button’s size and location is adjusted to the corresponding >region. > >"Oddball" wrote: > >> >> Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. >> >> What I want to draw as the item is another control. I have created a user control that I >> would like to list in this listbox but I can't for the life of me figure out how to draw the >> control inside ListBox... >> >> I get as far as: >> >> private void lbImageList_DrawItem(object sender, >> System.Windows.Forms.DrawItemEventArgs e) >> { >> // Set the DrawMode property to draw fixed sized items. >> lbImageList.DrawMode = DrawMode.OwnerDrawFixed; >> // Draw the background >> e.DrawBackground(); >> >> // Now draw my control in there... umm.... >> e. >> >> } >> >> Help! :) >> >> >> ------------------------------------ >> >> Another unchecked rambeling brought to you by: >> >> Oddball >> joshua@bf#N0SP4M#wd.co.uk >>
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
But what this doesn't do is allow me to work with 'sender' as if it where the user control
or work with the index of the listbox (because the listbox has not been clicked on.
I've wasted two days trying to work this out now - I'm very, very new to this so I don't
know how everything fits together properly.
Is there NO WAY to use the ListBox as it should be used? Can I definatly not get my
control to draw as if it were within the listbox? It seems like listboxes have been
designed to display items of almost any size, and have then had that ability left out at
the last second. I'm getting stressed now and I'm close to just going back to working
on websites... ASP.net is easyer that all this Windows Forms gubbins!
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?="
<Br**********@discussions.microsoft.com> wrote: For my example, I am using the MouseDown event from 3 buttons, the listbox and the user control. Within the InitializeComponent() function I have the following to setup my listening to the specific events within the user control.
this.listBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.button2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.button3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler);
You notice that all of them call the same function, which is written as:
private void MyMouseDownHandler(object sender, System.Windows.Forms.MouseEventArgs e) { this.OnMouseDown(sender, e); }
This makes it simple to choose which events and from what controls should trigger the events provided by the user control. One warning though, not all controls support the same events, the Click event for instance does not exist as part of the ListBox class, but does as part of many others.
"Oddball" wrote:
Could you give me an example of how I would do this?
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" <Br**********@discussions.microsoft.com> wrote:
>I would suggest using a usercontrol that contains all of these sub controls >you want, all of which pipe the events you care about back to the user >control. > >As an example, both your custom control and listbox both respond to the >Click event, so have both events trigger the click event of the parent user >control. > > >"Oddball" wrote: > >> >> Great! I've done that and the controls are now displaying properly. >> >> As a related query I now want the user to be able to click anywhere within my control >> and fire the same event. Seeing as how the control is being written on top of the >> ListBox I can't fire the usual ListBox events (click, drag, etc.) but my control is
made up >> of a number of other controls which all have their own events. >> >> How do I get back the standard ListBox controls?! :) >> >> I'm just never happy, am I :) >> >> "=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" >> <Br**********@discussions.microsoft.com> wrote: >> >> >If you already have a user control, there is no need to
‘draw’ it within the >> >listbox, instead, simply reposition the user control to the desired location >> >on top of the list box. >> > >> >This same method is often used if someone wants to add their own buttons to >> >a status bar, they create a new class that inherits from the regular >> >StatusBar class, and also contain the desired buttons, whenever a given panel >> >is painted, the button’s size and location is adjusted to
the corresponding >> >region. >> > >> >"Oddball" wrote: >> > >> >> >> >> Ok - I have a ListBox control and I'm ready to write my own DrawItem event >> handler. >> >> >> >> What I want to draw as the item is another control. I have created a user
control >> that I >> >> would like to list in this listbox but I can't for the life of me figure out how to
draw the >> >> control inside ListBox... >> >> >> >> I get as far as: >> >> >> >> private void lbImageList_DrawItem(object sender, >> >> System.Windows.Forms.DrawItemEventArgs e) >> >> { >> >> // Set the DrawMode property to draw fixed sized items. >> >> lbImageList.DrawMode = DrawMode.OwnerDrawFixed; >> >> // Draw the background >> >> e.DrawBackground(); >> >> >> >> // Now draw my control in there... umm.... >> >> e. >> >> >> >> } >> >> >> >> Help! :) >> >> >> >> >> >> ------------------------------------ >> >> >> >> Another unchecked rambeling brought to you by: >> >> >> >> Oddball >> >> joshua@bf#N0SP4M#wd.co.uk >> >> >> >> >> ------------------------------------ >> >> Another unchecked rambeling brought to you by: >> >> Oddball >> joshua@bf#N0SP4M#wd.co.uk >>
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
I apologize for my non timely response on this.
The major issue is that the ListBox control does not support the kind of
functionality you want to use it for. I agree, it stinks. I too have run into
quite a few things that I wanted to use it for, but that it simply didn’t
support and I didn’t have the time to build my own from scratch. Each time,
my only available option was to scale back what I wanted to do, make it work
and hope to find a better way later.
What it keeps sounding like you need is a ListBox style control that is also
a container, that is, permits controls to be placed within it, not unlike how
a Button or ListBox is placed within a form. I fear that I do not currently
know of such a control, meaning your best bet for having such a thing would
be to have it built, either by you or someone else.
I’m sorry that I wasn’t able to help you find the answers you are looking
for on this.
Brendan
"Oddball" wrote: But what this doesn't do is allow me to work with 'sender' as if it where the user control or work with the index of the listbox (because the listbox has not been clicked on.
I've wasted two days trying to work this out now - I'm very, very new to this so I don't know how everything fits together properly.
Is there NO WAY to use the ListBox as it should be used? Can I definatly not get my control to draw as if it were within the listbox? It seems like listboxes have been designed to display items of almost any size, and have then had that ability left out at the last second. I'm getting stressed now and I'm close to just going back to working on websites... ASP.net is easyer that all this Windows Forms gubbins!
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" <Br**********@discussions.microsoft.com> wrote:
For my example, I am using the MouseDown event from 3 buttons, the listbox and the user control. Within the InitializeComponent() function I have the following to setup my listening to the specific events within the user control.
this.listBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.button2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.button3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMou seDownHandler);
You notice that all of them call the same function, which is written as:
private void MyMouseDownHandler(object sender, System.Windows.Forms.MouseEventArgs e) { this.OnMouseDown(sender, e); }
This makes it simple to choose which events and from what controls should trigger the events provided by the user control. One warning though, not all controls support the same events, the Click event for instance does not exist as part of the ListBox class, but does as part of many others.
"Oddball" wrote:
Could you give me an example of how I would do this?
"=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" <Br**********@discussions.microsoft.com> wrote:
>I would suggest using a usercontrol that contains all of these sub controls >you want, all of which pipe the events you care about back to the user >control. > >As an example, both your custom control and listbox both respond to the >Click event, so have both events trigger the click event of the parent user >control. > > >"Oddball" wrote: > >> >> Great! I've done that and the controls are now displaying properly. >> >> As a related query I now want the user to be able to click anywhere within my control >> and fire the same event. Seeing as how the control is being written on top of the >> ListBox I can't fire the usual ListBox events (click, drag, etc.) but my control is made up >> of a number of other controls which all have their own events. >> >> How do I get back the standard ListBox controls?! :) >> >> I'm just never happy, am I :) >> >> "=?Utf-8?B?QnJlbmRhbiBHcmFudA==?=" >> <Br**********@discussions.microsoft.com> wrote: >> >> >If you already have a user control, there is no need to ‘drawââà ¢â‚¬Å¡Ã‚¬Ã¢â€žÂ¢ it within the >> >listbox, instead, simply reposition the user control to the desired location >> >on top of the list box. >> > >> >This same method is often used if someone wants to add their own buttons to >> >a status bar, they create a new class that inherits from the regular >> >StatusBar class, and also contain the desired buttons, whenever a given panel >> >is painted, the button’s size and location is adjusted to the corresponding >> >region. >> > >> >"Oddball" wrote: >> > >> >> >> >> Ok - I have a ListBox control and I'm ready to write my own DrawItem event >> handler. >> >> >> >> What I want to draw as the item is another control. I have created a user control >> that I >> >> would like to list in this listbox but I can't for the life of me figure out how to draw the >> >> control inside ListBox... >> >> >> >> I get as far as: >> >> >> >> private void lbImageList_DrawItem(object sender, >> >> System.Windows.Forms.DrawItemEventArgs e) >> >> { >> >> // Set the DrawMode property to draw fixed sized items. >> >> lbImageList.DrawMode = DrawMode.OwnerDrawFixed; >> >> // Draw the background >> >> e.DrawBackground(); >> >> >> >> // Now draw my control in there... umm.... >> >> e. >> >> >> >> } >> >> >> >> Help! :) >> >> >> >> >> >> ------------------------------------ >> >> >> >> Another unchecked rambeling brought to you by: >> >> >> >> Oddball >> >> joshua@bf#N0SP4M#wd.co.uk >> >> >> >> >> ------------------------------------ >> >> Another unchecked rambeling brought to you by: >> >> Oddball >> joshua@bf#N0SP4M#wd.co.uk >>
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk
------------------------------------
Another unchecked rambeling brought to you by:
Oddball joshua@bf#N0SP4M#wd.co.uk This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ivan Voras |
last post by:
Does wxPython (actually, the wx toolkit) support setting up ListCtrls or
similar to allow custom element drawing?
Something like generating an...
|
by: Toby Mathews |
last post by:
Hi,
In an ASP.Net application I want to convert open create a FileStream
object from a System.Drawing.Image - is this possible? I create an...
|
by: amber |
last post by:
Hello.
Can someone tell me what I may be doing wrong here?
I'm using the code (lboxRP is a listbox):
Dim newRPindex As Integer
newRPindex =...
|
by: Chris Leuty |
last post by:
I am populating a multiselect Listbox from a dataset, with the content of
the listbox filled by one table, and the selections determined from...
|
by: Kevin Johnson |
last post by:
H
I have an ASP.NET datagrid written in C#. When editing my datagrid it contains one dropdown list and 4 normal textboxes
I need the dropdown...
|
by: Mchuck |
last post by:
I've seen several newsgroup topics everywhere concerning
this, as well as a couple of articles from the MSDN
website, but this error still baffles...
|
by: Dave |
last post by:
Hi all,
After unsuccessfully trying to make my own dual listbox control out of
arraylists, I decided to look for a 3rd party control. I've...
|
by: Olie |
last post by:
I have a window drawing problem that I hope someone may be able to
help with.
I basically have a form and a control in the form which is docked...
|
by: BarryM |
last post by:
Iv got a panel on the main form which is set to auto scroll. In the panel there is a picture box that i draw lines in. the lines work perfectly fine...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: CD Tom |
last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
| |