TextBox边框颜色问题,高手指点

wanggk 2006-09-28 11:20:36
在WinForm中TextBox把属性设成FixedSingle,怎么能把那个黑框框改改颜色。
继承TextBox也可以,请高手讲讲怎么做
...全文
201 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小y的CSDN博客 2007-01-18
  • 打赏
  • 举报
回复
在webform里面好做 定义css就可以了
在winform里就麻烦一点了
正如楼上说的
把textBox的BorderStyle设置成none 然后在背景上画边框
nonocast 2007-01-18
  • 打赏
  • 举报
回复
把边框隐藏掉
在背景上画
北京的雾霾天 2007-01-18
  • 打赏
  • 举报
回复
我有一个代码楼主参考下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace TextBoxApp
{
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)
{
System.Console.WriteLine(m);
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);
}
}
}
}
}
}
}
sdl2005lyx 2007-01-18
  • 打赏
  • 举报
回复
lz:试了N长时间,找到一个办法:

private void Form10_Paint(object sender, PaintEventArgs e)
{
Rectangle rc = textBox1.Bounds;
rc.X -= 1; rc.Y -= 1;
rc.Inflate(1, 1);
e.Graphics.DrawRectangle(Pens.Red, rc);
}

不知道是否满足你的要求。?
bill024 2006-09-28
  • 打赏
  • 举报
回复
http://www.codeproject.com/cs/miscctrl/xp-style_button.asp
参考一下吧
wthorse 2006-09-28
  • 打赏
  • 举报
回复
想法好.继承完了告诉大家

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧