Mouse Events RRS feed

  • Question

  • I'm starting to learn how to do mouse events in vb.net and the first place I looked on msdn had a bit of code to get me rolling. Problem is I copy and pasted the code and get a three errors that I don't understand. It seems as though I'm missing a library or something I don't know where to start any help would be appreciated.

    "Load" cannot be found

    "TextBox1" is not declared

    "System.MouseEventArgs" is not defined

    Public Class Module1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            TextBox1.ContextMenu = New ContextMenu()
        End Sub
        Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.MouseEventArgs) Handles_   TextBox1.MouseDown
            If (e.Button = Windows.Forms.MouseButtons.Right) Then
                TextBox1.Select(0, TextBox1.Text.Length)
            End If
        End Sub
    End Class

    I'm guessing the TextBox1 is just a text box that I need to define somewhere but the other two problems I'm not sure of.

    Thanks in advance

    Friday, March 31, 2017 7:51 PM

All replies

  • Hi VBnoob101,

    I create a demo and reproduce your issue on my side, open the Form1.vb[Design] and drag textbox control to the design.

    Then click Form1 -> event -> select load -> select load method.

    The same as TextBox1.MouseDown Method.

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by NHT81 Monday, April 3, 2017 8:50 AM
    Monday, April 3, 2017 8:47 AM