让TextBox控件显示为一条横线(顶者没分) 1、不要更改属性的那种方法2、直接加载页面就显示为横线3、调试成功立即结帖4、分数只给代码最优者 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System.Windows.Forms;public class Test : Form{ Test() { TextBox tbx = new TextBox(); tbx.Parent = this; tbx.Multiline = true; tbx.Top = 50; tbx.Height = 1; } static void Main() { Application.Run(new Test()); }} 用 Label 效果更好:using System.Windows.Forms;public class Test : Form{ Test() { Label lbl = new Label(); lbl.Parent = this; lbl.BorderStyle = BorderStyle.Fixed3D; lbl.Anchor |= AnchorStyles.Right; lbl.Top = 50; lbl.Width = Width; lbl.Height = 3; } static void Main() { Application.Run(new Test()); }} using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;namespace JcsControlLibrary{ public partial class JcsLineTextBox : TextBox { public JcsLineTextBox() { InitializeComponent(); this.Width = 100; this.BorderStyle = BorderStyle.None; } private Color _linecolor = Color.Black ; /// <summary> /// 线条颜色 /// </summary> public Color LineColor { get { return this._linecolor; } set { this._linecolor = value; this.Invalidate(); } } private const int WM_PAINT = 0xF; protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_PAINT) { DrawLine(); } } private void DrawLine() { Graphics g = this.CreateGraphics(); using(Pen p = new Pen(this._linecolor )) { g.DrawLine(p,0,this.Height -1 ,this.Width ,this.Height -1); } } }} TO:chenxu4277 很感谢你的回复,但是没有实现… 所定义的自定义类JcsLineTextBox在主窗体怎么实现? 把你的代码在VS2008下运行时没有效果… 不知LZ是什么意思,要达到什么效果。难道是这样:using System.Windows.Forms;class TextBox : System.Windows.Forms.TextBox{ public TextBox() { Multiline = true; Height = 1; }}class Test : Form{ Test() { TextBox tbx1 = new TextBox(); tbx1.Parent = this; TextBox tbx2 = new TextBox(); tbx2.Parent = this; tbx2.Top = 50; TextBox tbx3 = new TextBox(); tbx3.Parent = this; tbx3.Top = 50; tbx3.Left = 150; } static void Main() { Application.Run(new Test()); }} TO EveryOne: 非常感谢大家的回答,本问题已由chenxu4277圆满解决 现在结帖… chenxu4277 重写控件 牛啊 用VS 2010生成的测试数据中字符类型全是乱码 格式不正确 想在datagridview上实现类似于excel的筛选的功能,请问该怎么做?windows 窗体程序 我想用c#做个类似qq的程序,请各位高手给个思路? C# excel 导入出错时怎样删除以前的导入 从网页上面抓取数据 在DataGrid中增加新行的问题? 怎样设置dataGrid控件中单元格的事件? C#文件操作 用datetimepiker绑定数据如果遇见“空”值时会出错,请问如何解决? 用SelectSingleNode()方法,如何获取XML指定值的节点 vs2003不能调试
{
Test()
{
TextBox tbx = new TextBox();
tbx.Parent = this;
tbx.Multiline = true;
tbx.Top = 50;
tbx.Height = 1;
} static void Main()
{
Application.Run(new Test());
}
}
{
Test()
{
Label lbl = new Label();
lbl.Parent = this;
lbl.BorderStyle = BorderStyle.Fixed3D;
lbl.Anchor |= AnchorStyles.Right;
lbl.Top = 50;
lbl.Width = Width;
lbl.Height = 3;
} static void Main()
{
Application.Run(new Test());
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;namespace JcsControlLibrary
{
public partial class JcsLineTextBox : TextBox
{
public JcsLineTextBox()
{
InitializeComponent();
this.Width = 100;
this.BorderStyle = BorderStyle.None;
}
private Color _linecolor = Color.Black ;
/// <summary>
/// 线条颜色
/// </summary>
public Color LineColor
{
get
{
return this._linecolor;
}
set
{
this._linecolor = value;
this.Invalidate();
}
}
private const int WM_PAINT = 0xF;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_PAINT)
{
DrawLine();
}
}
private void DrawLine()
{
Graphics g = this.CreateGraphics();
using(Pen p = new Pen(this._linecolor ))
{
g.DrawLine(p,0,this.Height -1 ,this.Width ,this.Height -1);
}
}
}
}
很感谢你的回复,但是没有实现…
所定义的自定义类JcsLineTextBox在主窗体怎么实现?
把你的代码在VS2008下运行时没有效果…
{
public TextBox()
{
Multiline = true;
Height = 1;
}
}class Test : Form
{
Test()
{
TextBox tbx1 = new TextBox();
tbx1.Parent = this; TextBox tbx2 = new TextBox();
tbx2.Parent = this;
tbx2.Top = 50; TextBox tbx3 = new TextBox();
tbx3.Parent = this;
tbx3.Top = 50;
tbx3.Left = 150;
} static void Main()
{
Application.Run(new Test());
}
}
非常感谢大家的回答,本问题已由chenxu4277圆满解决
现在结帖…