C#,textbox怎么把边框设置颜色,把四个角改成圆角,设置属性可以吗?

 我来答
匿名用户
推荐于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);
}
}
}
}
}
}
123456789fyD
2018-11-26
知道答主
回答量:13
采纳率:0%
帮助的人: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;

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-08-02
展开全部
哈哈,这简单!没有这个选项,除非自绘重写控件。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式