CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    36

    Extending Controls

    I want to extend the TextBox control, but it isn't as straight forward as I had hoped. Has anyone had any luck extending controls and know how to do it?

  2. #2
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    26
    Hi,

    As a matter of fact is kind of simple.
    I didn't extend a TextBox, but I have extended
    for example an OpenGLControl which extends the
    simple class Control.

    You have to tell him to extend the base class, in
    your case TextBox, like this:

    class MyClass : TextBox

    and then you have to look in the documentation
    of the TextBox to see if the methods you want
    to override are overridable, and if so, you
    write them again like this:

    for example, for the existing:
    protected virtual void OnClick( EventArgs e);
    you will write a function to override it:
    protected override void OnClick( EventArgs e)
    {
    //your code here
    }

  3. #3
    Join Date
    Oct 2001
    Posts
    36
    The part that I am really having trouble with is putting it on a form using the IDE. I have the class but can't seem to use it.

  4. #4
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    26
    It works just fine for me...

    I have in the main form
    private Control textbox1;

    then in some method I have:
    textbox1=(Control) (new MyClass());
    textbox1.SetBounds(10,10,50,20);
    Controls.Add(textbox1);

    the only thing different comparing to
    adding normal controls is that you convert
    it to a Control... but that is for having
    a variable independent from your class...
    it should work with:
    private MyClass textbox2=new MyClass();
    textbox2.SetBounds(10,10,50,20);
    Controls.Add(textbox2);
    as well...

    Good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured