我以前也碰到过这样的问题,可以自己DRAW一个,之后将其设置为一个对象,再加点属性什么的。相当于自己做个控件啦。

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;namespace BadEgg
    {
    /// <summary>
    /// line 的摘要说明。
    /// </summary>
    public class line : System.Windows.Forms.Control
    {
    /// <summary> 
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public line()
    {
    // 该调用是 Windows.Forms 窗体设计器所必需的。
    InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化
    this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor,true);
    this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint,true);

    } /// <summary> 
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region 组件设计器生成的代码
    /// <summary> 
    /// 设计器支持所需的方法 - 不要使用代码编辑器 
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    // 
    // line
    // 
    this.Name = "line";
    this.Size = new System.Drawing.Size(60, 20); }
    #endregion private int _width; protected override CreateParams CreateParams
    {
    get
    {
    CreateParams cp = base.CreateParams;
    cp.ExStyle |= 0x20;
    return cp;
    //return base.CreateParams;
    }
    }
    protected override void OnPaintBackground(PaintEventArgs pevent)
    {
    //base.OnPaintBackground (pevent);
    } protected override void OnPaint(PaintEventArgs e)
    {
    this.BackColor=Color.Transparent;
    Pen pen=new Pen(this.ForeColor,this._width);
    e.Graphics.DrawLine(pen,1,1,this.Width,this.Height);
    }

    public int LineWidth
    {
    get
    {
    return this._width;
    }
    set
    {
    this._width=value;
    this.Invalidate();
    }
    } }
    }
      

  2.   

    思想来源:http://community.csdn.net/Expert/topic/3162/3162314.xml?temp=.5277674不过没有解决一个问题,就是怎样让控件只有可见的部分可以响应事件.Making Transparent controls with C#
    http://www.c-sharpcorner.com/Code/2003/May/TransparentControls.asp
    3. Override the OnMove event with the following code.Protected override void OnMove(EventArgs e)
    {
    RecriateHandle();//这个不知所然
    }
      

  3.   

    吓!高手出现了, 感谢 abiho(橡木)!!!, 十分感谢, 希望大家都来分享一下!!!