OnPain() 可以的啊。你画的位置修改修改。我试过的。可以。自己做过。自己画边框替代原来的textbox的边框的。

解决方案 »

  1.   

    画边框要用GetWindowDC得到HDC 
    然后构造一个Graphics g = Graphics.FromHDC(hDC);
      

  2.   

    不要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);                
        } 
    }临时写的,没测试过,思路基本上就是这样了。
      

  3.   

    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);}}
      

  4.   

    对不起,GetWindowDC要引入哪个组件啊?或者是那个名称空间啊?
      

  5.   

    刚才试过了,用重载的方法不行,根本不触发  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
    }
    }
      

  6.   

    知道是API了,可是按照你的方法写出来,还是老样子。
      

  7.   

    to seamansoftcom(水手软件):有没有试试UserControl的方法
      

  8.   

    UserControl的方法太麻烦,主要是要和TextBox一样适用。这样以来,所有的方法,事件,属性都要重新写了。麻烦。