.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Shortcut Keys on TextBox in VB.NET Winforms

Posted By:Hefin Dsouza       Posted Date: September 25, 2009    Points: 25    Category: General    URL: http://www.dotnetspark.com  

The Article below will demonstrate the use of the KeyDown events for you to enable shortcut keys on a TextBox

The Following Code Has to be written in the KeyDown Event

Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.Control Then

If e.KeyCode = Keys.U Then
TextBox1.Text = TextBox1.Text.ToUpper()

End If

If e.KeyCode = Keys.L Then
TextBox1.Text = TextBox1.Text.ToLower()
End If

If e.KeyCode = Keys.R Then
Dim st As String
For Each c As Char In TextBox1.Text.Reverse() 'Using the Extension Method of LINQ only works in .NET 3.5
st &= c.ToString()
TextBox1.Text = st
End If

If e.KeyCode = Keys.B Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Bold)
End If

If e.KeyCode = Keys.I Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Italic)
End If
End If
End Sub
You can add as many Shortcut Keys you want
For ALT key combinations

If e.Alt Then ......
For Shift Key Combinations

If e.Shift Then ......
Hope this Article is Usefull...

Hefin Dsouza
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend