刚才帖子标题写错了.这个才是QQ签名式文本框控件,那个帖子是QQ好友列表控件,囧.
QQ签名式文本框控件,资源还在审核,一会儿放下载地址.
常态显示效果
鼠标掠过
编辑时效果
可修改属性
<ToolboxBitmap("D:\vb2010\QQ签名式文本框控件\QQ截图20111122221930.ico")>
Public Class TextboxOfQQStyle
Friend WithEvents lblMask As New Label
Protected WithEvents txtEdit As New TextBox
#Region "自定义的属性"
Private _Text As String = "SC Products"
''' <summary>
''' 显示在控件上的文字
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<System.ComponentModel.Browsable(True), System.ComponentModel.Description("显示在控件上的文字"), System.ComponentModel.Category("SC_外观")>
Public Shadows Property SC_Text() As String
Get
Return _Text
End Get
Set(ByVal value As String)
lblMask.Text = value
txtEdit.Text = value
If SC_AutoSize Then Me.Size = lblMask.Size
_Text = value
End Set
End Property
Private _HoverColor As Color = Color.FromArgb(100, Color.Orange)
''' <summary>
''' 鼠标掠过时的半透明颜色(当然您也可以指定一个不具有透明度的颜色)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<System.ComponentModel.Browsable(True), System.ComponentModel.Description("鼠标掠过时的半透明颜色"), System.ComponentModel.Category("SC_外观")>
Public Property SC_HoverColor() As Color
Get
Return _HoverColor
End Get
Set(ByVal value As Color)
_HoverColor = value
End Set
End Property
Private _EditingForeColor As Color = Color.Black
''' <summary>
''' 编辑时的文本颜色(此颜色不应带有透明通道值,如果带有则将会自动略去透明度)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<System.ComponentModel.Browsable(True), System.ComponentModel.Description("编辑时的文本颜色(此颜色不应带有透明通道值,如果带有则将会自动略去透明度)"), System.ComponentModel.Category("SC_外观")>
Public Property SC_EditingForeColor() As Color
Get
Return _EditingForeColor
End Get
Set(ByVal value As Color)
txtEdit.ForeColor = value
_EditingForeColor = value
End Set
End Property
Private _EditingBackColor As Color = Color.White
''' <summary>
''' 编辑时的背景颜色(此颜色不应带有透明通道值,如果带有则将会自动略去透明度)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<System.ComponentModel.Browsable(True), System.ComponentModel.Description("编辑时的背景颜色(此颜色不应带有透明通道值,如果带有则将会自动略去透明度)"), System.ComponentModel.Category("SC_外观")>
Public Property SC_EditingBackColor() As Color
Get
Return _EditingBackColor
End Get
Set(ByVal value As Color)
txtEdit.BackColor = value
_EditingBackColor = value
End Set
End Property
Private _AutoSize As Boolean = True
''' <summary>
''' 是否根据内容自动调整控件大小
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<System.ComponentModel.Browsable(True), System.ComponentModel.Description("是否根据内容自动调整控件大小"), System.ComponentModel.Category("SC_外观")>
Public Property SC_AutoSize() As Boolean
Get
Return _AutoSize
End Get
Set(ByVal value As Boolean)
lblMask.AutoSize = value
If value Then Me.Size = lblMask.Size
_AutoSize = value
End Set
End Property
Private _IsEditing As Boolean = False
''' <summary>
''' 指示控件的状态是否为正在编辑
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<System.ComponentModel.Browsable(True), System.ComponentModel.Description("指示控件的状态是否为正在编辑"), System.ComponentModel.Category("SC_外观")>
Public ReadOnly Property IsEditing() As Boolean
Get
Return _IsEditing
End Get
End Property
<System.ComponentModel.Browsable(False)>
Public Overrides Property Dock As System.Windows.Forms.DockStyle
Get
Return MyBase.Dock
End Get
Set(value As System.Windows.Forms.DockStyle)
MyBase.Dock = value
End Set
End Property
<System.ComponentModel.Browsable(False)>
Public Overrides Property Anchor As System.Windows.Forms.AnchorStyles
Get
Return MyBase.Anchor
End Get
Set(value As System.Windows.Forms.AnchorStyles)
MyBase.Anchor = value
End Set
End Property
<System.ComponentModel.Browsable(False)>
Public Overrides Property AutoSize As Boolean
Get
Return MyBase.AutoSize
End Get
Set(value As Boolean)
MyBase.AutoSize = value
End Set
End Property
<System.ComponentModel.Browsable(False)>
Public Overrides Property BackgroundImage As System.Drawing.Image
Get
Return MyBase.BackgroundImage
End Get
Set(value As System.Drawing.Image)
MyBase.BackgroundImage = value
End Set
End Property
<System.ComponentModel.Browsable(False)>
Public Overrides Property BackgroundImageLayout As System.Windows.Forms.ImageLayout
Get
Return MyBase.BackgroundImageLayout
End Get
Set(value As System.Windows.Forms.ImageLayout)
MyBase.BackgroundImageLayout = value
End Set
End Property
#End Region
Private Sub TextboxOfQQStyle_FontChanged(sender As Object, e As System.EventArgs) Handles Me.FontChanged
Call TextboxOfQQStyle_Resize(Nothing, Nothing)
End Sub
Private Sub TextboxOfQQStyle_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.Controls.Add(lblMask)
Me.Controls.Add(txtEdit)
lblMask.BackColor = Color.Transparent
lblMask.Size = Me.Size
lblMask.TextAlign = ContentAlignment.MiddleLeft
lblMask.Text = SC_Text
lblMask.AllowDrop = True
txtEdit.Size = lblMask.Size
txtEdit.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
txtEdit.Hide()
txtEdit.WordWrap = False
SC_EditingBackColor = txtEdit.BackColor
SC_EditingForeColor = txtEdit.ForeColor
Me.Font = New Font("微软雅黑", 12)
If SC_AutoSize Then Me.Size = lblMask.Size
End Sub
Private Sub lblMask_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles lblMask.MouseDown
txtEdit.Text = lblMask.Text
lblMask.Hide()
txtEdit.Show()
txtEdit.Focus()
Me.Height = txtEdit.Height
_IsEditing = True
End Sub
Private Sub lblMask_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles lblMask.DragDrop
If e.Data.GetData(GetType(String)) <> String.Empty Then
lblMask.Text = e.Data.GetData(GetType(String))
txtEdit.Text = lblMask.Text
Me.Height = txtEdit.Height
End If
End Sub
Private Sub lblMask_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles lblMask.DragEnter
If e.Data.GetData(GetType(String)) = String.Empty Then
e.Effect = DragDropEffects.None
Else
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub txtEdit_LostFocus(sender As Object, e As System.EventArgs) Handles txtEdit.LostFocus
lblMask.Text = txtEdit.Text
SC_Text = txtEdit.Text
lblMask.Show()
If SC_AutoSize Then Me.Size = lblMask.Size
txtEdit.Hide()
_IsEditing = False
End Sub
Private Sub TextboxOfQQStyle_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
Me.Height = txtEdit.Height
lblMask.Size = Me.Size
txtEdit.Size = lblMask.Size
'If SC_AutoSize AndAlso Not _IsEditing Then Me.Size = lblMask.Size
End Sub
Private Sub lblMask_MouseEnter(sender As Object, e As System.EventArgs) Handles lblMask.MouseEnter
lblMask.BackColor = SC_HoverColor
End Sub
Private Sub lblMask_MouseLeave(sender As Object, e As System.EventArgs) Handles lblMask.MouseLeave
lblMask.BackColor = Color.Transparent
End Sub
Private Sub txtEdit_TextChanged(sender As Object, e As System.EventArgs) Handles txtEdit.TextChanged
If SC_AutoSize Then
lblMask.Text = txtEdit.Text
Me.Size = lblMask.Size
End If
End Sub
End Class