C#,textbox怎么把边框设置颜色,把四个角改成圆角,设置属性可以吗?
3个回答
推荐于2017-06-09
展开全部
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);
}
}
}
}
}
}
展开全部
//重绘边框
private void panel1_Paint(object sender, PaintEventArgs e)
{
//调用
Draw(panel1.ClientRectangle, panel1.CreateGraphics(), 1);
}
//重绘边框
private void Draw(Rectangle rectangle, Graphics g, int _radius)
{
Pen shadowPen = new Pen(Color.Black);
g.DrawPath(shadowPen, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - 2, rectangle.Height - 1, _radius));
}
public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
{
GraphicsPath gp = new GraphicsPath();
gp.AddArc(x, y, radius, radius, 180, 90);
gp.AddArc(width - radius, y, radius, radius, 270, 90);
gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
gp.AddArc(x, height - radius, radius, radius, 90, 90);
gp.CloseAllFigures(); return gp;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
//调用
Draw(panel1.ClientRectangle, panel1.CreateGraphics(), 1);
}
//重绘边框
private void Draw(Rectangle rectangle, Graphics g, int _radius)
{
Pen shadowPen = new Pen(Color.Black);
g.DrawPath(shadowPen, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - 2, rectangle.Height - 1, _radius));
}
public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
{
GraphicsPath gp = new GraphicsPath();
gp.AddArc(x, y, radius, radius, 180, 90);
gp.AddArc(width - radius, y, radius, radius, 270, 90);
gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
gp.AddArc(x, height - radius, radius, radius, 90, 90);
gp.CloseAllFigures(); return gp;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-02
展开全部
哈哈,这简单!没有这个选项,除非自绘重写控件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询