creating my own textbox in VS.Net

J

Jonas L

Hi,

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
color.
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
beeping.
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#.

Regards
Jonas
 
R

Roy Osherove

Hi,

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
color.
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
beeping.
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#.

Regards
Jonas

regarding the beeping, you can make it go away by checking if the key
pressed is Keys.Return. If it is, set the event argument object ("e") to
e.Handled=true.
That should take care of that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top