让TextBox控件显示为一条横线(顶者没分)

wolfmvp 2009-02-14 11:25:30
1、不要更改属性的那种方法
2、直接加载页面就显示为横线
3、调试成功立即结帖
4、分数只给代码最优者
...全文
268 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
buzhidao945 2011-11-09
  • 打赏
  • 举报
回复
正好用上,可以试试
fxsee1 2009-10-06
  • 打赏
  • 举报
回复
学习下
chenxu4277 2009-02-14
  • 打赏
  • 举报
回复
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);
}
}
}
}


benislife 2009-02-14
  • 打赏
  • 举报
回复
lz的意思是一楼那样吗?
wuyi8808 2009-02-14
  • 打赏
  • 举报
回复
用 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());
}
}
wuyi8808 2009-02-14
  • 打赏
  • 举报
回复
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());
}
}
renzaijiang 2009-02-14
  • 打赏
  • 举报
回复
chenxu4277 重写控件 牛啊
wolfmvp 2009-02-14
  • 打赏
  • 举报
回复
TO EveryOne:
非常感谢大家的回答,本问题已由chenxu4277圆满解决
现在结帖…
feifeiyiwen 2009-02-14
  • 打赏
  • 举报
回复
情人节快乐!
liujiayu10 2009-02-14
  • 打赏
  • 举报
回复
自已写个输入框控件,控件由一条横线和普通文本框组成
perisonchen 2009-02-14
  • 打赏
  • 举报
回复
mark
king19840811 2009-02-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 WolfMvP 的回复:]
TO:chenxu4277
很感谢你的回复,但是没有实现…
所定义的自定义类JcsLineTextBox在主窗体怎么实现?
把你的代码在VS2008下运行时没有效果…
[/Quote]

需要用一个继承的控件的不能直接在代码里面用
wuyi8808 2009-02-14
  • 打赏
  • 举报
回复
不知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());
}
}
wolfmvp 2009-02-14
  • 打赏
  • 举报
回复
TO:chenxu4277
很感谢你的回复,但是没有实现…
所定义的自定义类JcsLineTextBox在主窗体怎么实现?
把你的代码在VS2008下运行时没有效果…

110,567

社区成员

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

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

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