Hello!
I have a very specific question and that is about how to inherit a control
for example the control System.Windows.Forms.TextBox without causing the
environment to delete the control when there are some compile errors. It's
the same problem with any visual control that you inherit. The control is
deleted as soon as you use the View Designer when there is compile error.
It's very easy to reproduce my problem. You can do it in this way.
1. Create a class called ExtTextBox like this. In my example here I have
removed the namespace. But if you include namespace make sure you have
access to it.
public class ExtTextBox : System.Windows.Forms.TextBox
{
public ExtTextBox() {}
}
As you can see this class ExtTextBox inherit from the ordinary components
System.Windows.Forms.TextBox in the .NET framework
2. Create a windows form with any name. The default is Form1
3. Use the View Designer and create the control TextBox in the window form.
My control was called textBox1
4. Because I want the control textBox1 to be an instance of ExtTextBox I
have to edit the InitializeComponent() I don't have any other idea.
Here is an extract from my windows form called Form1.
Only the interesting rows is written. Two rows is important here.
First saying that control textBox1 is of type ExtTextBox.
Second edit the InitializeComponent and say that textBox1 is an instance of
ExtTextBox.
public class Form1 : Form
{
private ExtTextBox textBox1; // First saying that control textBox1 is of
type ExtTextBox.
....
....
....
Private void InitializeComponent()
{
//Second edit the InitializeComponent and say that textBox1 is an instance
of ExtTextBox
this.textBox1= new ExtTextBox();
...
...
...
}
}
5 Compile. Hopefully you don't get any compile errors. When you run the
applikation only the testBox is being displayed. The problem might start
even here. If you get any compile error and you use the View Designer the
control named textBox1 is being deleted automatically.
6 If you don't get any compile error make a change so you get a compile
error and then use the View Designer the control named textBox1 is being
deleted automatically.
7 Now to my question. I can't use controls that being deleted automatically
when I get compile error.
8. If I want to use inheritance on visual control how do I do. I just can't
have it as it is now.
9 I just can't use inheritance in the way I do now.
10. I hope that you have a good suggestion how I should use inheritance on
visual control to avoid this kind of problems.
//Tony