dvlpr
July 30th, 2002, 11:15 AM
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?
|
Click to See Complete Forum and Search --> : Extending Controls dvlpr July 30th, 2002, 11:15 AM 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? trobert July 30th, 2002, 02:27 PM 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 } dvlpr July 30th, 2002, 11:34 PM 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. trobert July 31st, 2002, 02:43 AM 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 :) codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |