我新建一个WINDOWS应用程序 在FORM1里面放了一个文本框textbox1我想让文本框只显示下面的横线 具体该怎么做 我也只是有些写法 但是具体写在哪里 能不能详细的告诉我 先谢谢了!
解决方案 »
- 求SQL语句一个 (请用一条联合语句)
- 问个时下流行的“开心网外挂”问题,不知道是否违规
- C#中如何调用C语言编写的dll,该dll的函数接口中有一个函数指针类型的参数
- 菜鸟问水晶报表的问题。
- 不通过数据库,如何在本地完成对一系列数据的快速模糊查找?
- 极难问题啊,求教高手
- 神啊,使用递归帮我一下啊
- winform自定义控件事件的相关问题,在线等待。。。。。!!!!!!!
- C#windows应用台仿qq登陆注册程序求大神帮忙
- 我的Form被Panel遮住了,怎样才能够让Form收到mouse消息,而不是Panel?
- 这是什么情况?超级诡异的问题.
- ReportViewer打印RDLC的图片问题请教
设置好位置就行了
textBox 比较多的话这个方法就不怎么合适啦 :p
TextBox tb = new TextBox();
// tb.BackColor = this.BackColor;
tb.BorderStyle = BorderStyle.None;
tb.Margin = new Padding(0, 0, 0, 1);
tb.Width = 200;Panel p = new Panel();
p.AutoSize = true;
p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
p.BackColor = Color.Black;
p.Controls.Add(tb);
p.Location = new Point(10, 10);this.Controls.Add(p);
{
public LineTextBox()
{
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);
}
}
}
{
try {
foreach (Control T in this.Controls) {
if ((T) is TextBox) {
((TextBox)T).BorderStyle = BorderStyle.None;
e.Graphics.DrawLine(Pens.Black, new Point(T.Left, T.Top + T.Height + 1), new Point(T.Left + T.Width, T.Top + T.Height + 1));
}
}
} catch {
}
}
给窗体上所有TEXTBOX控件设置无边框及绘制下划线
将鼠标移到 Pens 上,按 Ctrl+Alt+F10,如果有菜单弹出来呢,选第一项,没有的话,再说。
private void splitContainer2_Panel1_Paint(object sender, PaintEventArgs e)
{
try
{
foreach (Control T in this.Controls)
{
if ((T) is TextBox)
{
((TextBox)T).BorderStyle = BorderStyle.None;
e.Graphics.DrawLine(Pens.Black, new Point(T.Left, T.Top + T.Height + 1), new Point(T.Left + T.Width, T.Top + T.Height + 1));
}
}
}
catch
{
} } private void ScheduleForm_Paint(object sender, PaintEventArgs e)
{
try
{
foreach (Control T in this.Controls)
{
if ((T) is TextBox)
{
((TextBox)T).BorderStyle = BorderStyle.None;
e.Graphics.DrawLine(Pens.Black, new Point(T.Left, T.Top + T.Height + 1), new Point(T.Left + T.Width, T.Top + T.Height + 1));
}
}
}
catch
{
}
}
e.Graphics.DrawLine?
foreach (Control T in this.Controls) ?你的 TextBox 在那个容器中啊? Form? splitContainer2 ?还有代码可以简化一下撒,看得好累
e.Graphics.DrawLine(
Pens.Black,
T.Left, T.Bottom, T.Right, T.Bottom);
11楼的方法,可以在FROM中正常使用,放到容器里就会有点问题
{
try {
foreach (Control T in this.Controls) {
if ((T) is TextBox) {
((TextBox)T).BorderStyle = BorderStyle.None;
e.Graphics.DrawLine(Pens.Black, new Point(T.Left, T.Top + T.Height + 1), new Point(T.Left + T.Width, T.Top + T.Height + 1));
}
}
} catch {
}
}因为纯手工写的代码,所以没有仔细核对,抱歉.红字部分改成 Sender 即可
拜托楼主多查查资料,自己也动动脑子撒!sender 是通用对象,要把 sender 转换成你需要的对象啊!下面2个方式可以实现对象转换
((SplitContainer)sender).Controls
(sender as SplitContainer).Controls需要注意的是:
sender 是引发事件的那个对象比如:由 Form 引发了 Paint 事件,则引发事件的是 Form 对象,此时
使用 (sender as Form).Controls 正确
使用 (sender as SplitContainer).Control 报错