Disable right button

Cassio

Junior Contributor
Joined
Nov 30, 2002
Messages
276
Location
Rio de Janeiro
I want to disable the buttons of the mouse when its clicked on a textbox, so the user wont select and copy its contents. Whats the best way to do this? What i´m doing is putting the foccus on another control, like this:

Visual Basic:
Private Sub txtpergunta_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtpergunta.MouseDown
        If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then
            cmdAvançar.focus()
        End If
    End Sub

But this is ugly.
 
This does what you wanted, but I don't know if it looks any prettier...

If btnMouse.MouseButtons.Left Or btnMouse.MouseButtons.Right Then
cmdExit.Focus()
End If

ailzaj
 
Or you can completely disable the context menu from showing in the textbox, eliminating the need to tranfer focus.

txtpergunta.ContextMenu = New ContextMenu()

Hope this works for you.
Dan
 
Only if you program txtpergunta to accept ctrl+c, or in you're case, program it not to accept ctrl+c via your forms keydown or keyup event handler.

esta bien?
Dan
 
Have you tried changing the TextBoxes enabled property to false?
Then it won't accept any mouse clicks or tab events.

ailzaj
 
Ok DiverDan, thanks.

I was also trying to do something like this:

Visual Basic:
If Not IsNothing(txtpergunta.SelectedText) Then
txtpergunta.Select(0,0)
End if
 
Check out this FAQ. The link points to the Textbox portion.

DiverDan has it half right - you want to disable the context menu. You'll also need to trap for keyboard to prevent Ctrl-C. It's in the FAQ (I think it's Ctrl-V for paste, but you can get it).

-Nerseus
 
Back
Top