peter-cooper
asked on
VS2010 WindowsForms MouseDown event not firing
I got some help yesterday with a problem I was having getting the name of multiple buttons. This code works fine if I create a new project and 2 new forms but when I place in my project, it doesn't fire at all. I have tried a try/catch statement, but no errors are being reported. How do I go about troubleshooting this. I have tried to rem out code and run after each comment but still the same. Any help would be greatly appreciated.
frmMain
frmRacks
frmMain
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each ctrl In Me.Controls
If TypeOf ctrl Is Button Then
AddHandler CType(ctrl, Button).MouseDown, AddressOf btn_MouseDown
End If
Next
'TODO: This line of code loads data into the 'StorageDataSet1.Customers' table. You can move, or remove it, as needed.
Me.CustomersTableAdapter.Fill(Me.StorageDataSet1.Customers)
'TODO: This line of code loads data into the 'StorageDataSet.User' table. You can move, or remove it, as needed.
Me.UserTableAdapter.Fill(Me.StorageDataSet.User)
'Dim frmDepartmentsLive As New frmDepartment
'frmDepartmentsLive.Owner = Me
'frmDepartmentsLive.ShowDialog()
lblDate.Text = Now
Timer1.Start()
rdoCustomer.Enabled = False
rdoCustomer.Checked = True
rdoDepartment.Enabled = False
rdoDepartment.Checked = False
End Sub
Private Sub btn_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Try
If (e.Button = MouseButtons.Right) Then
Dim btn = CType(sender, Button)
frmRacks.buttonName = btn.Name.Replace("btn", "")
frmRacks.Show()
ElseIf (e.Button = MouseButtons.Left) Then
MessageBox.Show("To be coded")
End If
Catch ex1 As exception
MsgBox("There's an error: " & vbCrLf & ex1.Message)
End Try
End Sub
frmRacks
Imports System.Data.OleDb
Public Class frmRacks
Public buttonName As String
Private Sub racksfrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblRacks.Text = buttonName
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
ASKER
Hi FernandoSoto
Sory, but I do not quite understand your answer. Could you please explain further. Thanks
Sory, but I do not quite understand your answer. Could you please explain further. Thanks
Where in frmMain do you define frmRocks?
ASKER
There is no frmRocks. It is frmRacks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much
Not a problem, glad to help.
In frmMain I can see that you are using a variable called frmRacks.buttonName = btn.Name.Replace("btn", "") and frmRacks.Show() but I do not see where you have declared frmRocks?