PC Review


Reply
Thread Tools Rate Thread

How to convert TextBox input to Upper Case?

 
 
=?Utf-8?B?ZWxlbmE=?=
Guest
Posts: n/a
 
      6th Dec 2004
Hi, All
Is it possible to convert input in the TextBox to Upper case, something
similare like in VB.6
Private Sub TextBox1_KeyPress(KeyAscii as Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End sub
I need to display all input in Upper Case for the user during the typing
process.
Please, advice

elena
 
Reply With Quote
 
 
 
 
Daniel Moth
Guest
Posts: n/a
 
      6th Dec 2004
Take a look at these:
http://groups-beta.google.com/group/...rch+this+group

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"elena" <(E-Mail Removed)> wrote in message
news:112A3CD8-9E00-4AA3-905F-(E-Mail Removed)...
> Hi, All
> Is it possible to convert input in the TextBox to Upper case, something
> similare like in VB.6
> Private Sub TextBox1_KeyPress(KeyAscii as Integer)
> KeyAscii = Asc(UCase(Chr(KeyAscii)))
> End sub
> I need to display all input in Upper Case for the user during the typing
> process.
> Please, advice
>
> elena



 
Reply With Quote
 
=?Utf-8?B?ZWxlbmE=?=
Guest
Posts: n/a
 
      7th Dec 2004
Thank you, Daniel
it helped.,

elena
"Daniel Moth" wrote:

> Take a look at these:
> http://groups-beta.google.com/group/...rch+this+group
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
>
> "elena" <(E-Mail Removed)> wrote in message
> news:112A3CD8-9E00-4AA3-905F-(E-Mail Removed)...
> > Hi, All
> > Is it possible to convert input in the TextBox to Upper case, something
> > similare like in VB.6
> > Private Sub TextBox1_KeyPress(KeyAscii as Integer)
> > KeyAscii = Asc(UCase(Chr(KeyAscii)))
> > End sub
> > I need to display all input in Upper Case for the user during the typing
> > process.
> > Please, advice
> >
> > elena

>
>
>

 
Reply With Quote
 
Stuart Celarier
Guest
Posts: n/a
 
      8th Dec 2004
I tracked down Daniel's references and this seems to be the best method:

using System.Windows.Forms;

public class UpperCaseTextBox : TextBox
{
protected override void OnKeyPress( KeyPressEventArgs e )
{
if ( char.IsLower( e.KeyChar ) )
{
int start = SelectionStart;
Text = Text.Insert( start, char.ToUpper( e.KeyChar ).ToString() );
SelectionStart = start + 1;
e.Handled = true;
}
else
base.OnKeyPress( e );
}
}

This approach is more efficient than another popular solution which
overrides the OnTextChanged method and converts the entire Text string
to uppercase each time it is changed.

Use UpperCaseTextBox as you would a TextBox. For example:

using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox;

public Form1()
{
textBox = new UpperCaseTextBox();
textBox.Location = new Point( 10, 10 );
Controls.Add( textBox );
Text = "Form1";
}

static void Main()
{
Application.Run( new Form1() );
}
}

Cheers,
Stuart Celarier, Fern Creek

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert lower to upper case automatically without using UPPER Sal Microsoft Excel Misc 6 26th Jul 2009 11:27 AM
convert upper case text to lower case with the first letter upper =?Utf-8?B?Skg=?= Microsoft Access Macros 1 20th Aug 2006 09:07 PM
How to convert lower case index entry tag to upper case? =?Utf-8?B?WXVyaSBJdmFub3Y=?= Microsoft Word Document Management 3 31st Jul 2006 10:55 PM
excel'03 how to convert a column from upper case to proper case =?Utf-8?B?c2hhcmllIHBhbG1lcg==?= Microsoft Excel Misc 1 30th Jan 2006 11:50 PM
How do I convert all upper case excel sheet into upper and lower . =?Utf-8?B?RGViRGF5?= Microsoft Excel Misc 1 9th Mar 2005 08:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:20 AM.