winform程序,如何让控件TextBox控件只有下边的线。 OnPain() 可以的啊。你画的位置修改修改。我试过的。可以。自己做过。自己画边框替代原来的textbox的边框的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 画边框要用GetWindowDC得到HDC 然后构造一个Graphics g = Graphics.FromHDC(hDC); 不要DC,太复杂,最简单是重载TextBoxpublic class TextBoxEx: TextBox{ protected override void OnPaint(PaintEventArgs e) { BorderStyle = BorderStyle.None; Graphics g = e.Graphics; g.DrawLine(Pens.Black, 0, Height, Width); } }临时写的,没测试过,思路基本上就是这样了。 public class TextBoxEx: TextBox{protected override void OnPaint(PaintEventArgs e){BorderStyle = BorderStyle.None;IntPtr hDC = GetWindowDC(this.Handle);Graphics g = Grphics.FromHDC(hDC);g.DrawLine(Pens.Black, 0, Height, Width);g.Dispose();ReleaseDC(hDC);}} 对不起,GetWindowDC要引入哪个组件啊?或者是那个名称空间啊? 刚才试过了,用重载的方法不行,根本不触发 OnPaint 事件。不过我想了一个好办法,一定能实现楼主的需要,哈哈:思路:作一个 UserControl,上面放一个 TextBox,把它的AutoSize设置为 false, Dock 设置为 Fill,然后把 UserControl 的 DockPadding 的 Button 设置为1,把 UserControl 的背景色设置为 黑色,就得到楼主要的效果了。using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Data;using System.Windows.Forms;namespace WindowsApplication46{ /// <summary> /// UserControl1 的摘要说明。 /// </summary> public class UserControl1 : System.Windows.Forms.UserControl { private System.Windows.Forms.TextBox textBox; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public UserControl1() { // 该调用是 Windows.Forms 窗体设计器所必需的。 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } [Browsable(true)] public string TextBox { get { return textBox.Text; } set { textBox.Text = value; } } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region 组件设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器 /// 修改此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // textBox // this.textBox.AutoSize = false; this.textBox.BorderStyle = System.Windows.Forms.BorderStyle.None; this.textBox.Dock = System.Windows.Forms.DockStyle.Fill; this.textBox.Location = new System.Drawing.Point(0, 0); this.textBox.MaxLength = 0; this.textBox.Name = "textBox"; this.textBox.Size = new System.Drawing.Size(184, 15); this.textBox.TabIndex = 0; this.textBox.Text = ""; // // UserControl1 // this.BackColor = System.Drawing.Color.Black; this.Controls.Add(this.textBox); this.DockPadding.Bottom = 1; this.Name = "UserControl1"; this.Size = new System.Drawing.Size(184, 16); this.ResumeLayout(false); } #endregion }} 知道是API了,可是按照你的方法写出来,还是老样子。 to seamansoftcom(水手软件):有没有试试UserControl的方法 UserControl的方法太麻烦,主要是要和TextBox一样适用。这样以来,所有的方法,事件,属性都要重新写了。麻烦。 请教一个对象的问题!! 简单问题(关于u盘) 用VS2010编译出来的程序因别人电脑中(WIN XP系统)没有.NET4.0框架于是无法运行。 ArrayList 值==文本??? 怎么保存C#处理完的图片啊! 定时执行的 Ajax方法 不能取当前 控件内容?? 类似[FlagsAttribute]的中括号表示什么? 求解:listview取值 想写一个函数把SQL操作简单化 但遇到一个难题 请大家指教 C#的出路在哪儿? 关于PropertyGrid控件的使用 一篇让我流泪的帖子。
然后构造一个Graphics g = Graphics.FromHDC(hDC);
{
protected override void OnPaint(PaintEventArgs e)
{
BorderStyle = BorderStyle.None;
Graphics g = e.Graphics;
g.DrawLine(Pens.Black, 0, Height, Width);
}
}临时写的,没测试过,思路基本上就是这样了。
{
protected override void OnPaint(PaintEventArgs e)
{
BorderStyle = BorderStyle.None;
IntPtr hDC = GetWindowDC(this.Handle);Graphics g = Grphics.FromHDC(hDC);
g.DrawLine(Pens.Black, 0, Height, Width);g.Dispose();
ReleaseDC(hDC);}}
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;namespace WindowsApplication46
{
/// <summary>
/// UserControl1 的摘要说明。
/// </summary>
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox textBox;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public UserControl1()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } [Browsable(true)]
public string TextBox
{
get
{
return textBox.Text;
}
set
{
textBox.Text = value;
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox
//
this.textBox.AutoSize = false;
this.textBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox.Location = new System.Drawing.Point(0, 0);
this.textBox.MaxLength = 0;
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(184, 15);
this.textBox.TabIndex = 0;
this.textBox.Text = "";
//
// UserControl1
//
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.textBox);
this.DockPadding.Bottom = 1;
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(184, 16);
this.ResumeLayout(false); }
#endregion
}
}