2
作爲VB的新用戶,我很努力地想知道爲什麼這個代碼可以在一個項目中工作,而不是在另一個項目中工作。如果我創建一個新項目和2個新窗體,但是當我放置在我的項目中時,此代碼工作正常,但無論是左鍵還是右鍵單擊都不會觸發。.Net WindowsForms MouseDown事件沒有觸發
我試過try/catch語句,但沒有錯誤報告。如何解決這個問題以找出錯誤。我試圖去掉代碼並在每個評論之後運行,但仍然是相同的。我甚至嘗試刪除表單上的所有其他代碼,只留下2個子集但沒有喜悅。任何幫助將不勝感激。
frmMain
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'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
For Each ctrl In Me.Controls
If TypeOf ctrl Is Button Then
AddHandler CType(ctrl, Button).MouseDown, AddressOf btn_MouseDown
End If
Next
End Sub
Private Sub btn_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
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
End Sub
frmRacks
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
是控制另一個控制或某事的孩子? –
@ta no。這只是一個按鈕ctrl。謝謝 – user1532468
開始設置一個斷點上如果(e.Button = MouseButtons.Right)然後'看看它是否有火災,然後一步一步看看有什麼問題 – Plutonix