【发布时间】:2015-09-20 08:27:46
【问题描述】:
我有在鼠标点击时更改文本框边框颜色的代码
但我不知道如何实现它以及在哪里实现它
代码如下:
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 并且只有 textbox ,所以在哪里实现
帮帮我..
【问题讨论】:
-
你想在哪个控件上改变颜色?
-
如果有人点击文本框,它应该变成绿色,如果没有点击,它应该变成蓝色
-
HiLightTextBox_GotFocus 应该可以处理 HiLightTextBox.GotFocus。并且其中的一些“我”应该是 HiLighttextBox(例如位置/大小)。
标签: vb.net