首页 > 开发 > 综合 > 正文

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

2020-02-03 13:37:14
字体:
来源:转载
供稿:网友
我在写的过程中发现了这个控件并不用 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 来选择框架的颜色。




菜鸟学堂:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表