I've been experimenting with having a standard API for a balloon tip on my Winform. No problems with standard textboxes, but I was wondering if it is at all possible to create one for a rich textbox? I would like a balloon tip to display when the Capslock is on.

Recommended Answers

All 6 Replies

You want to know when someone pressed caps lock in the rich textbox? Or just when caps lock is on and the rich textbox gets focus?

To see what some pressed while in the rich textbox you should use the KeyDown or KeyPress events of the rich text box and code something like this:

if Control.IsKeyLocked(Keys.CapsLock) Then 
    MessageBox.Show("The Caps Lock key is ON.") 
Else 
    MessageBox.Show("The Caps Lock key is OFF.") 
End If 

You just have to set the tooltip text on the mouse enter event for that control. If you set it to a null string then no tooltip is shown. Try the following:

Private Sub RichTextBox1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.MouseEnter

    Dim ctrl As RichTextBox = sender

    If My.Computer.Keyboard.CapsLock Then
        ToolTip1.SetToolTip(ctrl, "Caps Lock is On")
    Else
        ToolTip1.SetToolTip(ctrl, "")
    End If

End Sub

Thanks guys. I will give the code a try tonight. The rich textbox is an item the user can type a brief report. Since going live with the program, and in only a few cases, the user typed the whole report in Caps Lock, so I thought having the balloon tip pop up (like on Windows) with the message that Caps Lock is on, can warn the user before they go any further.

I've used the 'is keylocked' before, but the messagebox is not what I'm gearing towards. Same thing with the tooltip. Just interested if it is possible to use the windows api balloontip for a rich textbox. Without posting the code for creating the balloontip, here's what I've got for calling it.

Private m_eb As EditBalloon = New EditBalloon

    Public Sub New()
        MyBase.New()

        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

        m_eb.Title = "Caps Lock Is On"
        m_eb.TitleIcon = ToolTipIcon.Warning
        m_eb.Text = "Do not type report in ALL caps"
        m_eb.Parent = Me.EVENT_LOCATION

    End Sub
    Private Sub Event_Location_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Event_Location.KeyPress

        If (e.KeyChar = "&"c Or e.KeyChar = "%"c) Then
            m_eb.Show()
        End If
    End Sub

The "event location" is a standard textbox i've been toying with and the "e.keychar" again was just for trial and error, to see results. Again, I can get the balloontip to display in a textbox, but not the rich textbox.

Got it to work using the KeyPress event instead of MouseEnter. Now just have to obtain the caps lock state and set a delay on the balloon. Thanks for the help again!

if Control.IsKeyLocked(Keys.CapsLock) OrElse My.Computer.Keyboard.CapsLock then
    'The Caps lock is on....
End if
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.