C#,textbox怎么把边框设置颜色,把四个角改成圆角,设置属性可以吗?
1个回答
展开全部
textbox 系统控件,直接改肯定是没办法的,只能自己重写控件,继承TextBox
而且圆角应该只能完全重写控件
给你个改边框颜色的代码
public
class
MyTextBox
:
TextBox
{
public
MyTextBox()
{
this.BorderStyle
=
BorderStyle.FixedSingle;
}
protected
override
void
WndProc(ref
Message
m)
{
base.WndProc(ref
m);
if
(m.Msg
==
0xf
||
m.Msg
==
0x14
||
m.Msg
==
0x85)
{
if
(this.BorderStyle
==
BorderStyle.FixedSingle)
{
using
(Graphics
g
=
Graphics.FromHwnd(this.Handle))
{
using
(Pen
pen
=
new
Pen(Color.Red))
{
g.DrawRectangle(pen,
0,
0,
this.Width
-
1,
this.Height
-
1);
}
}
}
}
}
}
而且圆角应该只能完全重写控件
给你个改边框颜色的代码
public
class
MyTextBox
:
TextBox
{
public
MyTextBox()
{
this.BorderStyle
=
BorderStyle.FixedSingle;
}
protected
override
void
WndProc(ref
Message
m)
{
base.WndProc(ref
m);
if
(m.Msg
==
0xf
||
m.Msg
==
0x14
||
m.Msg
==
0x85)
{
if
(this.BorderStyle
==
BorderStyle.FixedSingle)
{
using
(Graphics
g
=
Graphics.FromHwnd(this.Handle))
{
using
(Pen
pen
=
new
Pen(Color.Red))
{
g.DrawRectangle(pen,
0,
0,
this.Width
-
1,
this.Height
-
1);
}
}
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询