Craig_Sparks
asked on
Right Clicking on a button from a Form problem
VB.NET 2003
So why in the world you cant start with the regular:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Code here
End Sub
and replace 'Code here with something to detect if it was a right click? Further why can you do something exactly like above but replace "Handels Button1.Click" with something like "Handels Button1.RightClick"?
I did figure out that I needed to add my own event handler:
AddHandler Button1.MouseDown, AddressOf myEvents.myMouseDown1
Then added a Class:
Public Class myMouseEventClass
Public Sub myMouseDown1(ByVal sender As Object, ByVal ex As MouseEventArgs)
If ex.Button = MouseButtons.Right Then
'Code here
End If
End Sub
End Class
Works fine but here is my problem, from within this class I cant touch any variables unless they are globally declared as Shared. Further I can call any other subroutines unless they are shared as well.
My main problem is that I would like to update part of the main form of my program, namely a Label1.Text with something from within the 'Code here section in the event handler. I also need to peform another button click from within the clase as well, namely Button2.PeformClick() but the same problem.
Trying to do either gives me:
Reference to a non-shared member requires an object reference
from the IDE and a subsequent:
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
From the Build Errors.
How can I get aroud this and do one simple thing, update a text box when I right click on a button.
Thanks for any insight anyone has.
Craig
So why in the world you cant start with the regular:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Code here
End Sub
and replace 'Code here with something to detect if it was a right click? Further why can you do something exactly like above but replace "Handels Button1.Click" with something like "Handels Button1.RightClick"?
I did figure out that I needed to add my own event handler:
AddHandler Button1.MouseDown, AddressOf myEvents.myMouseDown1
Then added a Class:
Public Class myMouseEventClass
Public Sub myMouseDown1(ByVal sender As Object, ByVal ex As MouseEventArgs)
If ex.Button = MouseButtons.Right Then
'Code here
End If
End Sub
End Class
Works fine but here is my problem, from within this class I cant touch any variables unless they are globally declared as Shared. Further I can call any other subroutines unless they are shared as well.
My main problem is that I would like to update part of the main form of my program, namely a Label1.Text with something from within the 'Code here section in the event handler. I also need to peform another button click from within the clase as well, namely Button2.PeformClick() but the same problem.
Trying to do either gives me:
Reference to a non-shared member requires an object reference
from the IDE and a subsequent:
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
From the Build Errors.
How can I get aroud this and do one simple thing, update a text box when I right click on a button.
Thanks for any insight anyone has.
Craig
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER