我嘗試使用BorderColor屬性創建標籤,但它不起作用。我在表單應用程序中創建了該標籤的即時對象,並嘗試更改BorderColor,但沒有發生任何事情。 這是我的代碼:使用BorderColor屬性創建自定義標籤
Public Class MyLabel
Inherits Label
Private _BorderColor As Color
Dim e As New PaintEventArgs(Me.CreateGraphics, Me.DisplayRectangle)
Public Property BorderColor As Color
Get
Return _BorderColor
End Get
Set(value As Color)
_BorderColor = value
CreateBorder(value)
End Set
End Property
Private Sub CreateBorder(ByVal value As Color)
Dim g As Graphics = Me.CreateGraphics
Dim p As Pen = New Pen(value, 2)
g.DrawRectangle(p, Me.DisplayRectangle)
End Sub
Private Sub MyLabel_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
CreateBorder(_BorderColor)
End Sub
末級
......你也不會改變PaintEventArgs的 – Plutonix
使用的Invalidate()從來沒有,刷新()。 –
@HansPassant,我想說,在應用程序代碼中,如果您特別想確保現在進行重繪,則可以調用'Refresh'。儘管在控制代碼中,你可能是正確的,「Invalidate」更合適。我已經做了上面的改變。 – jmcilhinney