Re: Event to return value
From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 07/09/04
- Next message: cody: "Re: why can I overload the != operator??"
- Previous message: William Ryan eMVP: "Re: HELP!!, I need create a conection to OLAP from aspx or asp"
- In reply to: Ken Kolda: "Re: Event to return value"
- Next in thread: Ken Kolda: "Re: Event to return value"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 9 Jul 2004 17:14:39 -0400
If you need to have everything capitalized then setting the CharacterCasing
is the way to go . I agree with you though about the positioning.
-- W.G. Ryan, eMVP Have an opinion on the effectiveness of Microsoft Embedded newsgroups? Let Microsoft know! https://www.windowsembeddedeval.com/community/newsgroups "Ken Kolda" <ken.kolda@elliemae-nospamplease.com> wrote in message news:%237eQP2dZEHA.4032@TK2MSFTNGP11.phx.gbl... > See comments inline... > > > private void textBox1_KeyPress(object sender, > > System.Windows.Forms.KeyPressEventArgs e) > > > > { > > > > e.Handled = true; > > > > ((TextBox)sender).Text += e.KeyChar.ToString().ToUpper(); > > > > } > > The event handler code above isn't sufficient because you don't know that > when the user pressed the key that the cursor is at the end of the textbox. > You'll need to use the SelectionStart and SelectionLength properties to > ensure that your character is placed in the correct location (and whatever > text was selected is removed), e.g. > > public static void uCaseReturn(object sender, > System.Windows.Forms.KeyPressEventArgs e) > { > if (!Char.IsControl(e.KeyChar)) > { > TextBox tb = (TextBox) sender; > int charPosition = tb.SelectionStart; > > // Build the new text for the box by replacing the selected text > with the character (in uppercase) > tb.Text = tb.Text.Substring(0, charPosition) + > Char.ToUpper(e.KeyChar) + > tb.Text.Substring(tb.SelectionStart + tb.SelectionLength); > > // Place the cursor in the correct location > tb.SelectionLength = 0; > tb.SelectionStart = charPosition; > > // Mark the keystroke as being handled > e.Handled = true; > } > } > > Ken > >
- Next message: cody: "Re: why can I overload the != operator??"
- Previous message: William Ryan eMVP: "Re: HELP!!, I need create a conection to OLAP from aspx or asp"
- In reply to: Ken Kolda: "Re: Event to return value"
- Next in thread: Ken Kolda: "Re: Event to return value"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|