Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Right Click VB 6.0

  • 03-01-2004 3:01am
    #1
    Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭


    Is there any easy way of disabling right click in VB 6?

    Im trying to prevent pasting into text boxes.


Comments

  • Registered Users, Registered Users 2 Posts: 1,726 ✭✭✭gerryk


    oveload the handler for the right mouse button event to do nothing


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    You could simply use RichTextBox.
    Right click is not enabled by default.

    If you don't know where RichTextBox is ...
    Right click on your ToolBox
    choose "components..."
    tick "Microsoft Rich textbox control"

    But user can still paste with keyboard by "Ctrl+V" or "Shift+Insert"
    So you would have handel it in the KeyPress or KeyDown event


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    Hmmmm might try rich textboxes. The shortcuts are sorted for most of them(Most have limited charcter entry, numbers only letters only etc, funnily enough it seems to prevent key combos aswell). I suppose i should find a more efficient way of doing it though.

    Thanks


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Unfortuantely you can't overload the event handler in VB6. One way I can think of doing this is intercepting the windows message to prevent the popup menu being, well, popped up. You'd have to go into the API to do this but there's another way to achieve the same results...

    What you can do is copy the contents of the text box in the mousedown event into a form level variable, and set a boolean (again form level) to indicate if its the right button. Then overwrite the paste in the textbox's change event.

    here's my form1.frm
    Option Explicit
    Dim mbChange As Boolean
    Dim sContent As String
    
    
    Private Sub Text1_Change()
        
        If mbChange Then
            Text1.Text = sContent
            Exit Sub
        End If
            
    End Sub
    
    Private Sub Text1_MouseDown(Button As Integer, _
                                Shift As Integer, _
                                X As Single, _
                                Y As Single)
    
        If Button = vbRightButton Then
            sContent = Text1.Text
            mbChange = True
        End If
    
    End Sub
    


    While this won't disable the popup menu it will prevent the paste taking place.


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    Hmmmmm im not really getting this. What does mbChange equal? The mouse button the user has pressed?

    How exactly does this stop the paste from taking place?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Okay, what happens is when you right click on a the textbox text1, you set mbChange to true and copy the contents of text1 into sContent. Then when the user pastes into the textbox this fires the change event.
    Now in the change event you query mbChange, if its set to true it means the right button has been clicked so you overwrite the contents of text1 with its previous contents stored in sContent. This overrides the paste. Cut and past the code into a vb form and try it for yourself.

    You'll need to add the following events too, so you can still use the textbox :D
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
        mbChange = False
    End Sub
    
    Private Sub Text1_LostFocus()
        mbChange = False
    End Sub
    

    and then change the mousedown event to look like the following.
    Private Sub Text1_MouseDown(Button As Integer, _
                                Shift As Integer, _
                                X As Single, _
                                Y As Single)
        mbChange = False
        If Button = vbRightButton Then
            sContent = Text1.Text
            mbChange = True
        End If
    
    End Sub
    


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    Right well that seemed to work a treat. Only problem is after it stops the paste you cant type into the text box without clicking on it again.

    Any way of simulating a left mouse click without the user actually having to click?


Advertisement