Declarations and initializations

  • Thread starter Thread starter mrond
  • Start date Start date
M

mrond

Hi everyone, I'm pretty new to C#.


I'm building a simple class called NumBox which is just a textbox that
can only accept digits. No problems building.

BUT, when I want to use it in an application and I put it in the form,
the visual studio automatically recognizes it as an inheritant from a
text box, and therefore, in the initializing stage, gives it a
default text (usually the name of the box).
Is there anything I can put in my class that can over-ride this?
 
In the form designer, go the the properties window (wherever it may be - it
may not be visible, if not press F4 to show it, and then change the Text
property (to an empty string if you like)
 
There are possibly many ways to do this (e.g. overriding the inherited
member responsible for setting this default text), however possibly the
simplest way would be to set the text property of the custom text box text
in it's constructor.

e.g.
public class CustomTextBox: System.Windows.Forms.TextBox
{
public CustomTextBox()
{
this.Text = "my string";
}
}

The overriding method is probably cleaner but more work.

Br,

Mark.
 
Back
Top