I wanted a TextBox with just digits as entry. So i wrote following code in the KeyPress events of the textbox
if(!char.IsDigit(e.KeyChar))
{
e.handled = true;
}
and it worked great. But I generally need them in many places of my application so then i wrote a partial class with following codes:
public partial class digitTextBox : TextBox
{
public digitTextBox()
{
this.KeyPress += new KeyPressEventHandler(digitTextBox_KeyPress);
}
void digitTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
}
build my solution and I got a control in my toolbox and even this was working perfectly fine.
But i had many TextBoxes with some or the other specification like, some should not accept special characters, some should accept decimals, some with decimals up to 2 digits after point….and so on and i do need these kind of controls in many applications.
So I thought of writing a Library(.dll) of my custom controls and if possible even for there validations. Honestly speaking I don’t have much idea about using libraries. So I made a library with 2 different kind of textboxes and created a .dll file out of them. Now I created a different winform application and I added reference of my custom control .dll file. But nothing happened.
So i just wanted to know what should be my approach in achieving it. Is there a better way to achieve these kind of tasks. and any new suggestions are also welcome. Thanks in advance.
Try right-mouse clicking the ToolBox and select “Choose Items…” and then select your controls from the available list. If you don’t see them, then click on the Browse button and select your DLL.
On a side note, you might be able to combine your two textboxes by adding properties: