Yoavo said:
I have a dialog with 2 TextBox controls.
I want to add some functionality to one of the them.
I created a class MyTextBox which inherits from TextBox.
How can I connect one of the TextBox controls to my new class ?
You don't exactly "connect" the textbox with the new class. Instead, the
textbox has to be an instance of the new class. Search your source code for
the place where the textbox is declared and initialized. If you are using
Visual Studio 2002/2003, this is in the .cs file for your Form in the block
labelled "designer generated code". If You are using VS 2005, you have to
click on the icon "show all files" in solution explorer, and then open the
file with the extension .designer.cs. You will find declarations similar to
this ones:
TextBox texbox1;
...
textbox1 = new TextBox();
In those two lines, replace TexBox with MyTextBox, and you are done.
Another way to do it is to compile your new class into a dll, and then
add it to the toolbx in the windows forms designer (right-click on the
toolbox). Once you do that, the MyTextBox will appear in the toolbox, and
you can drag it from there into your form just like the standard textbox. If
you are using version 2005, you don't need to do any of this, since the
controls defined inside your project will appear automatically at the top of
the toolbox, under "myproject components".