Subclassing System.Windows.Forms.ListBox 
Author Message
 Subclassing System.Windows.Forms.ListBox

I am trying to create a class derived from ListBox in which I can override
MeasureItem and DrawItem (as I could do SO easily in C++). I have several
examples in which these items are overridden in the context of
System.Windows.Forms.Form, but I want to do this in my derived class (public
class myListBox : ListBox), where the approach is not the same. Can anyone
help, or better yet,
does anyone have a simple example
Thanks,
Chris Hough


Tue, 21 Sep 2004 07:19:06 GMT  
 Subclassing System.Windows.Forms.ListBox
Hi,

In C# ListBox class has many events.  You can use these instead.

using System.Windows.Forms;
public class MyListBox : ListBox {

    public MyListBox()
    {
        this.DrawItem+= new DrawItemEventHandler (this.OnDrawItem);
        this.MeasureItem+= new MeasureItemEventHandler (this.OnMeasureItem);
    }

    public function OnDrawItem(object sender, DrawItemEventsArgs arg) {
        //draw item...
        //arg will contain the stuff needed
    }

    public function OnMeasureItem (object sender, MeasureItemEventArgs arg)
    {
        //
    }

Quote:
}

Greetz.


Quote:
> I am trying to create a class derived from ListBox in which I can override
> MeasureItem and DrawItem (as I could do SO easily in C++). I have several
> examples in which these items are overridden in the context of
> System.Windows.Forms.Form, but I want to do this in my derived class
(public
> class myListBox : ListBox), where the approach is not the same. Can anyone
> help, or better yet,
> does anyone have a simple example
> Thanks,
> Chris Hough



Tue, 21 Sep 2004 08:15:55 GMT  
 Subclassing System.Windows.Forms.ListBox

Quote:

> I am trying to create a class derived from ListBox in which I can override
> MeasureItem and DrawItem (as I could do SO easily in C++). I have several
> examples in which these items are overridden in the context of
> System.Windows.Forms.Form, but I want to do this in my derived class (public
> class myListBox : ListBox), where the approach is not the same. Can anyone
> help, or better yet,
> does anyone have a simple example
> Thanks,
> Chris Hough

http://samples.gotdotnet.com/quickstart/howto/doc/WinForms/WinFormsOw...

might help

Regards,

Jon Embury



Tue, 21 Sep 2004 08:39:40 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. System.Windows.Forms.Form

2. system.windows.forms.form.show()

3. Displaying XML in a System.Windows.Forms.Form control

4. Extending System.Windows.Forms.Form?

5. System.WinForms / System.Windows.Forms

6. How to convert System.Windows.Forms.Message to System.Windows.Forms.Keys?

7. override System.Windows.Forms.Treenode.Text

8. System.Windows.Forms & Inheritance problem

9. Directory Selection in System.Windows.Forms.OpenFileDialog

10. Where is System::Windows::Forms???

11. Few questions reguarding System::Windows::Forms::Control...(

12. System.Windows.Forms.Application in Class lib

 

 
Powered by phpBB® Forum Software