我是 Visual Basic.NET 和編程的新手。
我有一個帶有 4 個按鈕的表單,相同的影像已分配給這些按鈕。
使用 Flatstyle.Flat、Flatstyle.Standard 和 Flatstyle.Popup 可以正確顯示影像。
使用 Flatstyle.System 不顯示影像。
我試圖找到解決這個問題的方法。為此,我嘗試了 2 個解決方案:
- 我畫了一個影像(img1),但我不知道如何將它放在前景中,以便它位于控制按鈕上方。
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim img1 As Image = My.Resources.image
Dim g As Graphics = e.Graphics
g.DrawImage(img1, New Rectangle(260, 180, 24, 24))
End Sub
- 我在按鈕(系統)中繪制了圖示(img2),但我不知道如何在打開程式時顯示它,當我單擊按鈕3(彈出視窗)時它會出現,當我將滑鼠懸停在繪制它的按鈕(Button4,System)。
Private Sub Popup_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim img2 As Image = My.Resources.image
Dim g As Graphics = Button4.CreateGraphics()
g.DrawImage(img2, 9, 13, 24, 24)
End Sub
看一下附圖:Form1
謝謝你的幫助
uj5u.com熱心網友回復:
如果要在 a 上繪圖Button,請處理 that 的Paint事件,而Button不是表單的事件。永遠不要打電話CreateGarphics。
另外,不要My.Resources一遍又一遍地訪問相同的屬性。它每次都會從資源中提取一個新物件。訪問該屬性一次并將值分配給一個欄位,然后重復使用該欄位。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/503732.html
標籤:VB.net
