Question about constructor of extended control...

todonnell69

Member
Joined
Jun 8, 2005
Messages
15
Programming Experience
5-10
I created a simple extended textbox control by using Inherits System.Windows.Forms.TextBox and then just added some of my own functionality. I did not use the visual designer at all.
My question is, when I instantiate the control, it has the standard 'Textbox1' as the default text. I tried using me.text = "" in the control's sub New, but that didn't remove the text.
Is the constructor the correct place for the 'me.text = ""' ?
...If not, why wouldn't it work there?
Thanks...
 
Maybe you want to try ... Me.TextBox1.Text = String.Empty 'or ""
As if you say only Me.Text = "" it means that you refer to the current form's text property

Btw, you should never use the original name for custom control but rather name it something like myTextBox or numText or something but never same with the original ...


Cheers ;)
 
kulrom said:
Maybe you want to try ... Me.TextBox1.Text = String.Empty 'or ""
As if you say only Me.Text = "" it means that you refer to the current form's text property

...but I am coding in the inherited class for the textbox, not in the form code at this point, so the 'me' would refer to the textbox still, I think.
So, would I have to get rid of the default control name text in the form's code, or could it be done in the textbox class itself? I would have thought that the sub New for the inherited control would be the place to do it, but it's not working.
Thanks again...
 
If a control has a Text property then the IDE fills that Text property automatically. It simply sequentially names controls by appending the next available number to the class name. There is nothing in the TextBox class that enters that Text either, it's all done by the IDE. Just clear the Text property in the design window when you add an instance to a form, the same way you do with other controls.
 
Back
Top