DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How to add shorcut key for changing a word to bold When i press Ctrl+B (Like in Word)

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Location
    Hyderabad
    Posts
    6

    Thumbs up How to add shorcut key for changing a word to bold When i press Ctrl+B (Like in Word)

    Hi to all,
    I hve a requirement like this,
    In my vb.net 2.0 Im using a richTextbox Control.
    In this How can i add a short cut key to change a to Changr a word to bold when i press ctrl+B.
    Please send me a solution.
    Thanx in Advance.

  2. #2
    Join Date
    Dec 2005
    Location
    South of Nowhere, Maine
    Posts
    309
    You need to take the selected text, and make it bold. I think there is a SelectedText property of the RTF box.

    How you trigger that (using keypress events, or a toolbar, etc) is up to you.

  3. #3
    Join Date
    Nov 2003
    Posts
    154
    Here's an example that toggles text from regular to bold (or vice versa) when the user types Ctrl-B.

    Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
    If e.KeyCode = System.Windows.Forms.Keys.B Then
    If e.Control Then
    If Not RichTextBox1.SelectionFont Is Nothing Then
    Dim currentFont As System.Drawing.Font = RichTextBox1.SelectionFont
    Dim newFontStyle As System.Drawing.FontStyle

    If RichTextBox1.SelectionFont.Bold = True Then
    newFontStyle = FontStyle.Regular
    Else
    newFontStyle = FontStyle.Bold
    End If

    RichTextBox1.SelectionFont = New Font( _
    currentFont.FontFamily, _
    currentFont.Size, _
    newFontStyle _
    )
    End If
    End If
    End If
    End Sub

    This example only works on selected text but you should be able to make it toggle individual words, sentences, or paragraphs with a little work.
    A. Russell Jones,
    Executive Editor,
    Internet.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center