Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

All capitals by Key Press

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Manu Singhal - 13 Aug 2005 05:59 GMT
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
Maqsood Ahmed - 13 Aug 2005 06:36 GMT
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
Octavio Hernandez - 13 Aug 2005 09:16 GMT
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

> Hi
>
[quoted text clipped - 28 lines]
>
> Manu Singhal
Visually Seen # - 13 Aug 2005 11:03 GMT
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 #

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.