|
-
July 30th, 2002, 11:15 AM
#1
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?
-
July 30th, 2002, 02:27 PM
#2
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
}
-
July 30th, 2002, 11:34 PM
#3
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.
-
July 31st, 2002, 02:43 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|