WinForm中自定义文本框中怎么绘制图形?比如一条直线.
有解出再加50分,谢~~~~~~~~~~~~~~~~

解决方案 »

  1.   

    继承自Textbox的控件在onpain事件中的操作无效.MSDN有这样一句话:注意   某些 Windows 窗体控件(如 TextBox)是由 Windows 直接绘制的。在这些情况中,永远不调用 OnPaint 方法,
      

  2.   

    可以的吧,我这段代码试过了,当鼠标移上去时画一直线
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;namespace contro_lset
    {
    /// <summary>
    /// mybutton 的摘要说明。
    /// </summary>
    public class mybutton : System.Windows.Forms.TextBox
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;
    public mybutton()
    {
    // 该调用是 Windows.Forms 窗体设计器所必需的。
    InitializeComponent();
    this.Width=100;
    this.Height=75;
    MouseEnter+=new EventHandler(OnMouseEnter);

    // TODO: 在 InitComponent 调用后添加任何初始化
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if( components != null )
    components.Dispose();
    }
    base.Dispose( disposing );
    } #region 组件设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器 
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    components = new System.ComponentModel.Container();
    }
    #endregion protected override void OnPaint(PaintEventArgs pe)
    {
        pe.Graphics.DrawLine(new Pen(Color.Blue),0,4,80,5);

    }
    private void OnMouseEnter(object o,System.EventArgs e)
    {
             OnPaint(new PaintEventArgs(this.CreateGraphics(),this.ClientRectangle)); }
    }
    }