当前位置:编程学习 > C#/ASP.NET >>

如何让TextBox的黑色边框变成淡蓝色(borderstyle=FixedSingle)

答案:我在写的过程中发现了这个控件并不用 Paint 事件,所以只好直接截取 WndProc 函数了,很简单,是这样的:

Public Class TextBoxBlue
  Inherits TextBox

  Protected Overrides Sub WndProc(ByRef m As system.Windows.Forms.Message)
    MyBase.WndProc(m)
    Const WM_PAINT As Integer = &HF
    If m.Msg = WM_PAINT AndAlso Me.BorderStyle = BorderStyle.FixedSingle
Then
      Dim g As Graphics = Graphics.FromHwnd(Me.Handle)
      g.DrawRectangle(Pens.Blue, Me.ClientRectangle.Left,
Me.ClientRectangle.Top, Me.ClientRectangle.Width - 1,
Me.ClientRectangle.Height - 1)
      g.Dispose()
    End If
  End Sub
End Class

也可以自己添加一个属性叫做 BorderColor 来选择框架的颜色。

上一个:子窗体刷新父窗体的问题完全解决了,谢谢E版主
下一个:启动关联的应用程序打开特殊文件 zlyperson(原作)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,