VB.NET ...請不要使用C。我制作了一個包含動態創建按鈕的選單,總共有 18 個按鈕。當滑鼠懸停/滑鼠懸停事件發生時,我需要更改任何按鈕的背景,但不知道如何添加此功能。
我目前的代碼如下:
Dim btnBilling As New ToolStripButton
With btnBilling
'Set properties
.BackgroundImage = My.Resources.ToolBarBkGrd2
.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
.TextImageRelation = TextImageRelation.ImageBeforeText
.Image = My.Resources.Billing
.Font = New Font("Calibri", 8.25, FontStyle.Bold)
.Text = "Billing" & vbNewLine & "Info"
End With
'Create Handle to Click Event
AddHandler btnBilling.Click, AddressOf BtnBilling_Click
'Add button to toolstrip
ToolStrip1.Items.Add(btnBilling)
'Billing Button Events
Private Sub BtnBilling_Click(sender As Object, e As EventArgs)
Bill()
End Sub
Public Sub Bill()
If ActiveMdiChild IsNot Nothing Then ActiveMdiChild.Close()
Billing.MdiParent = Me
Billing.Show()
End Sub
我將如何以及在何處添加滑鼠懸停事件處理程式。目前計劃的唯一滑鼠懸停事件是將背景影像更改為 My.Resources.ToolBarBkGrd3
選單位于始終可見的父表單上。只有當前的子表單會關閉并加載到新的子表單中。
uj5u.com熱心網友回復:
這就是我最終解決問題的方式。特別感謝約翰朝正確的方向輕推。
Private BkGrd = resources.GetObject("ToolBarBkGrd2")
Private Bkgrd1 = resources.GetObject("ToolBarBkGrd3")
Dim btnBilling As New ToolStripButton
With btnBilling
'Set properties
.BackgroundImage = CType(BkGrd, Drawing.Image)
.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
.TextImageRelation = TextImageRelation.ImageBeforeText
.Image = My.Resources.Billing
.Font = New Font("Calibri", 8.25, FontStyle.Bold)
.Text = "Billing" & vbNewLine & "Info"
End With
'Create handle for MouseEnter Event
AddHandler btnBilling.MouseEnter, AddressOf BtnBilling_MouseEnter
'Create handle for MouseLeave Event
AddHandler btnBilling.MouseLeave, AddressOf BtnBilling_MouseLeave
'Create a Handle to a Click Event
AddHandler btnBilling.Click, AddressOf BtnBilling_Click
'Billing Button Events
Private Sub BtnBilling_MouseEnter(sender As Object, e As EventArgs)
With sender
'Set properties
.BackgroundImage = CType(BkGrd1, Drawing.Image)
End With
End Sub
Private Sub BtnBilling_MouseLeave(sender As Object, e As EventArgs)
With sender
'Set properties
.BackgroundImage = CType(BkGrd, Drawing.Image)
End With
End Sub
Private Sub BtnBilling_Click(sender As Object, e As EventArgs)
Bill()
End Sub
Public Sub Bill()
If ActiveMdiChild IsNot Nothing Then ActiveMdiChild.Close()
Billing.MdiParent = Me
Billing.Show()
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/505717.html
下一篇:XML文本閱讀器覆寫跳過子元素
