|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
On the fly formatting of textbox contentsI have textbox1 that takes a phone number xxx-xxx-xxxx. Is it possible
to have it start off looking like - - and when someone types the number fill in around the -s? If not how about after they type the 3rd number have the - fill in automatically etc. Lastly if that isn't doable then where is the best place to put code to reformat the number after they are finished entering it. Perhaps textbox1_leave doesn't appear to work? I got textbox1_leave working. I'd still like answers to my first two
options if anyone knows how. cj wrote: Show quoteHide quote > I have textbox1 that takes a phone number xxx-xxx-xxxx. Is it possible > to have it start off looking like - - and when someone types the > number fill in around the -s? > > If not how about after they type the 3rd number have the - fill in > automatically etc. > > Lastly if that isn't doable then where is the best place to put code to > reformat the number after they are finished entering it. Perhaps > textbox1_leave doesn't appear to work? Hi,
Just as MVP Cor suggested, in Visual Studio 2005 you can use the MaskedEditBox--just set its Mask as 000-000-000. If you work with VS.NET 2003, I think you can set the textbox's default text as "000-000-000", then handle that textbox's event as follows: Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar > "9" Or e.KeyChar < "0" Then e.Handled = True End If End Sub Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If TextBox1.Text.Length = 3 Then TextBox1.Text += "-" TextBox1.Select(TextBox1.Text.Length, 0) End If If TextBox1.Text.Length = 7 Then TextBox1.Text += "-" TextBox1.Select(TextBox1.Text.Length, 0) End If End Sub By the way, in the textbox's TextChanged event handler, you also need to check and modify the string if the user paste stuff to it. Thanks! Best regards, Gary Chang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. thanks
Gary Chang[MSFT] wrote: Show quoteHide quote > Hi, > > Just as MVP Cor suggested, in Visual Studio 2005 you can use the > MaskedEditBox--just set its Mask as 000-000-000. > > If you work with VS.NET 2003, I think you can set the textbox's default > text as "000-000-000", then handle that textbox's event as follows: > > Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As > System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress > > If e.KeyChar > "9" Or e.KeyChar < "0" Then > e.Handled = True > End If > End Sub > > Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As > System.EventArgs) Handles TextBox1.TextChanged > > If TextBox1.Text.Length = 3 Then > TextBox1.Text += "-" > TextBox1.Select(TextBox1.Text.Length, 0) > End If > > If TextBox1.Text.Length = 7 Then > TextBox1.Text += "-" > TextBox1.Select(TextBox1.Text.Length, 0) > End If > End Sub > > By the way, in the textbox's TextChanged event handler, you also need to > check and modify the string if the user paste stuff to it. > > Thanks! > > Best regards, > > Gary Chang > Microsoft Online Community Support > ================================================== > When responding to posts, please "Reply to Group" via your newsreader so > that others may learn and benefit from your issue. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. > You are welcome!
Good Luck! Best regards, Gary Chang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Ho do I create a program that can get recognized as a printer driver and installed with the add prin
incompatibility with dotnet 2.0 and Outlook Business Contact Manager 2003 How can I embedd graphics in Outlook Email without using MAPI Register DLL for COM interop and use it in ASP help in search&replace for ArrayList Troubled saving a clipped region from an image to disk as transparent Help with creating Installation package under VB2005 Express Ed. System.Configuration.ConfigurationSettings.AppSettings.Get("...") Question about the data adaptor Fill method. ComboBox values and Items |
|||||||||||||||||||||||