Hi


I am trying to build a windows forms control which derieves from TextBox.
The added functionality that i want is that

I want every character that appears on the TextBox should be in Capitals.


For this i have created a Class iTextBox and Derieved from TextBox and have
overriden the OnKeyPress Method Here is the code :-

protected override void OnKeyPress(KeyPressEventArgs e)

{


if(Char.IsLetter(e.KeyChar))

{

e = new KeyPressEventArgs(Char.ToUpper(e.KeyChar));


}

base.OnKeyPress (e);


}



But when i test the class it the method runs but the characted is not
converted to Upper case.







Please help and advice.





Manu Singhal

Re: All capitals by Key Press by Maqsood

Maqsood
Sat Aug 13 00:36:58 CDT 2005

Hello,
You can do it with another approach.

<code lang='C#'>
protected override OnKeyPress(KeyPressEventArgs e)
{
if(Char.IsLetter(e.KeyChar) && Char.IsLower(e.KeyChar))
{
this.Text += Char.ToUpper(e.KeyChar);
this.SelectionStart = this.Text.Length;
e.Handled = true;
}
else
base.OnKeyPress(e);
}
</code>

Don't make an inherited textbox if you are doing it only for this
purpose, it can be achieved via KeyPressed event. You will only need to
ignore the 'else' part from the code in that case.

HTH. Cheers.
Maqsood Ahmed [MCP C#,SQL Server]
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***

Re: All capitals by Key Press by Octavio

Octavio
Sat Aug 13 03:16:27 CDT 2005

Manu,

You can use the CharacterCasing property of the TextBox for that:

textBox1.CharacterCasing = CharacterCasing.Upper

The version you have writtten only seems to lack the assignment:

e.Handled = true;

in the event handler.

Regards - Octavio

"Manu Singhal" <manu.isoft@gmail.com> escribió en el mensaje
news:%23tlWNP8nFHA.3936@TK2MSFTNGP10.phx.gbl...
> Hi
>
>
> I am trying to build a windows forms control which derieves from TextBox.
> The added functionality that i want is that
>
> I want every character that appears on the TextBox should be in Capitals.
>
>
> For this i have created a Class iTextBox and Derieved from TextBox and
> have overriden the OnKeyPress Method Here is the code :-
>
> protected override void OnKeyPress(KeyPressEventArgs e)
>
> {
>
>
> if(Char.IsLetter(e.KeyChar))
>
> {
>
> e = new KeyPressEventArgs(Char.ToUpper(e.KeyChar));
>
>
> }
>
> base.OnKeyPress (e);
>
>
> }
>
>
>
> But when i test the class it the method runs but the characted is not
> converted to Upper case.
>
>
>
>
>
>
>
> Please help and advice.
>
>
>
>
>
> Manu Singhal
>
>



Re: All capitals by Key Press by Visually

Visually
Sat Aug 13 05:03:28 CDT 2005

Manu,

An even easier option is to go to the Properties window while your text
box is still selected and go down to Behaviour, and change the
CharacterCasing from Normal to Upper,

Visually Seen #