none
Creating objects using mouse click or mouse events in Visual Basic 2010 RRS feed

Answers


  • Yes, you can make a class/object that has mouse events. The event in the form for the event would pass its event (signature) to the method in the object that represents the event.

    The Model View Presenter design pattern is a classic example of passing this type of execution to another object, which is segregated away from the form itself by using an Interface.

    Thursday, March 14, 2013 4:03 PM
  • Hi, here is an example that creates a button where you click.

    Public Class Form1
    
        Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
            Dim B As New Button
            With B
                .Width = 70
                .Height = 30
                .Text = "OK"
                .Left = e.Location.X
                .Top = e.Location.Y
            End With
            Controls.Add(B)
        End Sub
    
    End Class

    Saturday, March 16, 2013 9:17 AM

All replies


  • Yes, you can make a class/object that has mouse events. The event in the form for the event would pass its event (signature) to the method in the object that represents the event.

    The Model View Presenter design pattern is a classic example of passing this type of execution to another object, which is segregated away from the form itself by using an Interface.

    Thursday, March 14, 2013 4:03 PM
  • That depends what you call an object. 

    An object is every not linving thing. 

    In .Net it means a construction by a class which derives from system object. 

    Of course can you create new ones by handling the event which happens when you click on the mouse.


    Success
    Cor

    Thursday, March 14, 2013 4:24 PM
  • Hi, here is an example that creates a button where you click.

    Public Class Form1
    
        Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
            Dim B As New Button
            With B
                .Width = 70
                .Height = 30
                .Text = "OK"
                .Left = e.Location.X
                .Top = e.Location.Y
            End With
            Controls.Add(B)
        End Sub
    
    End Class

    Saturday, March 16, 2013 9:17 AM