By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,434 Members | 1,586 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,434 IT Pros & Developers. It's quick & easy.

creating my own textbox in VS.Net

P: n/a

I need to create a textbox which acts as a normal textbox but with the
following extra requirements:

1) In-focus color, when the textbox gets focus the backcolor property
of the textbox should be set to a, selectable, in-focus color.
2) Out-of-focus color, when the textbox loses focus the backcolor
property of the textbox should be set to a, selectable, out-of-focus
3) Enter pressed, the textbox should also have the property that when
the enter key is pressed focus should move to the next control without
4) Toolbox, this new textbox should easily be drag'n'dropped from the
Toolbox on to a Form in VS.NET, as a normal textbox.
5) Databinding, the databinding properties of the textbox should be
easily accessed in VS.NET, as a normal textbox.

As I see it there are two ways of solving this. I can create my
textbox by inheriting (Soluiton A) from System.Windows.Forms.TextBox
or (Solution B) from System.Windows.Forms.UserControl.

The A solution allows me to implement requirements 1-3 by using the
textbox events "Enter", "Leave" and "Key Pressed", but it is still
beeping when using the "Key Pressed" event! Regarding requirement 4, I
have no idea how to achieve this. Is there an interface that I should
implement inorder to make this work? Requirement 5, I can solves this
by first drag'n'dropp a normal textbox on to my form and then I can,
manually, change the type of this textbox e.g. from
System.Windows.Forms.TextBox to myTextBox. But this solution costs
alot of time when one might have 5-10 textbox's on each form and I
have over 20 form's. Isn't there a better way of doing this?

The B solution allows me to put a textbox in my user control. So,
requirements 1-3 can be implemented using different events from the
userControl and the textbox. Requirement 4 is easy in this case, I can
just select "Add/Remove Item" on the toolbox and so on. Regarding the
fifth requirement, the databinding, only the databinding properties
that belongs to the user control is editable in the properties when my
new textbox is placed in a form. How can I make the databinding work
in VS.Net on the textbox which is inside the user control?

Can anyone help me? I am writing the code in C#.

Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.