我有代碼,以便在鼠標改變文本框的邊框顏色單擊改變文本框的邊框顏色
,但我無法獲取如何實現它,並在那裏實現它
這裏是代碼:
using controlpaint.DrawBorder ,you can draw with penwidth greater than 1
Public Class HighlightTextBox
Inherits System.Windows.Forms.TextBox
'Default Highlight color is red.>>
Private Highlight_Color As Color = Color.Red
Public Property HighLightColor() As Color
Get
Return Me.Highlight_Color
End Get
Set(ByVal value As Color)
Me.Highlight_Color = value
End Set
End Property
Private Pen_Width As Integer = 1
Public Property PenWidth() As Integer
Get
Return Me.Pen_Width
End Get
Set(ByVal value As Integer)
Me.Pen_Width = value
End Set
End Property
Private Sub HiLightTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
Dim g As Graphics = Me.Parent.CreateGraphics
Dim Rect As New Rectangle(Me.Location.X - Me.Pen_Width, Me.Location.Y - Me.Pen_Width, Me.Width + Me.Pen_Width * 2, Me.Height + Me.Pen_Width * 2)
Windows.Forms.ControlPaint.DrawBorder(g, Rect, Me.Highlight_Color, Me.Pen_Width, Windows.Forms.ButtonBorderStyle.Solid, Me.Highlight_Color, Me.Pen_Width, _
Windows.Forms.ButtonBorderStyle.Solid, Me.Highlight_Color, Me.Pen_Width, Windows.Forms.ButtonBorderStyle.Solid, Me.Highlight_Color, Me.Pen_Width, Windows.Forms.ButtonBorderStyle.Solid)
End Sub
Private Sub HiLightTextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
Dim g As Graphics = Me.Parent.CreateGraphics
Dim Rect As New Rectangle(Me.Location.X - Me.Pen_Width, Me.Location.Y - Me.Pen_Width + Me.Pen_Width, Me.Width, Me.Height + Me.Pen_Width)
g.DrawRectangle(New Pen(Parent.BackColor, Me.Pen_Width), Rect)
Parent.Refresh()
End Sub
Private Sub HiLightTextBox_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
Me.Refresh()
Call HiLightTextBox_GotFocus(Nothing, Nothing)
End Sub
End Class
我Form1並在世界上只有文本框,所以它在哪裏實現
幫助我..
要在哪個控件上更改顏色? – hdkhardik
如果有人點擊文本框,它應該變成綠色,如果沒有點擊,它應該變成藍色 – Aditya
HiLightTextBox_GotFocus應該可能處理HiLightTextBox.GotFocus。並且其中的一些「我」應該是HiLighttextBox(例如位置/大小)。 – Fruitbat