不是这样的,是在 Paint 事件里画直线。
当类中有关划线的属性发生了变化时,调用 this.Refresh() 方法,通知控件按照属性值重绘就可以了。

解决方案 »

  1.   

    那怎么在DLL的类里,对窗体的PAINT事件进行操作呢,而且是不知道具体什么窗体的情况下?
      

  2.   

    新建一个 用户控件,代码如下using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace GraphicsTest
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    InitializeComponent();
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Name = "Form1";
    this.Text = "Form1"; }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }
    }
    }
      

  3.   

    上面的是Form1,这个才是你要的
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;namespace GraphicsTest
    {
    /// <summary>
    /// MyLine 的摘要说明。
    /// </summary>
    public class MyLine : System.Windows.Forms.UserControl
    {
    private System.ComponentModel.Container components = null; public MyLine()
    {
    this.Name = "MyLine";
    this.Size = new System.Drawing.Size(48, 48);
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.MyLine_Paint);
    } protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } private void MyLine_Paint(object sender, PaintEventArgs e)
    {
    e.Graphics.DrawLine( new Pen(Color.Blue),new Point(0,0),new Point(100,100));
    }
    }
    }
      

  4.   

    还是不对,首先那个FORM1为什么要放在命名空间中呢?如果是这样那放个PANEL也行,关键是不知道用户要把class MyLine 对象放在什么FORM或者PANEL上。
    第二那个class MyLine 对象继承System.Windows.Forms.UserControl的话,就无所谓FORM1了,因为USERCONTROL本身就可以随便放啊,
    我要的class MyLine就是个CLASS,不继承任何对象,只是通过里面的属性方法事件来达到我说的目的,行否哩?
      

  5.   

    见我写的这个。http://community.csdn.net/Expert/topic/3533/3533062.xml?temp=.6155359
      

  6.   

    public class PaintControler
    {
    public PaintBorard paintBoard;
    public ShapeCollection  shapes;
    public PaintControler()
    { }
    public void Connect()
    {
    // paintBoard.MouseDown += ...;
    paintBoard.Paint += new PaintEventHandler(OnPaint); }
    public void DrawFocus(Graphics g)
    { }
    public void OnPaint(object obj,PaintEventArgs e)
    {
    foreach(Shape s in shapes)
    {
    s.Paint(e.Graphics);
    }
    }
    }
    public class Line : Shape
    {
    }
    public class ShapeCollection : IList
    {
    }
      

  7.   

    AutoCad类的软件基本就是基于这样的设计。。