参考:
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=8772

解决方案 »

  1.   

    我放点吧,只好看,不好用。using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication6
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; Point p1;
    Point p2; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(648, 341);
    this.Name = "Form1";
    this.Text = "Form1";
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.SetP1);
    this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SetP2); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void SetP1(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    p1.X=e.X;
    p1.Y=e.Y;
    } private void SetP2(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    p2.X=e.X;
    p2.Y=e.Y;
    ddl();


    }
    private void ddl()
    {
    Random r=new Random();
    Color asd=Color.FromArgb(r.Next (255),r.Next (255),r.Next (255),r.Next (255));
    Pen p=new Pen (asd,r.Next (30));
    p.SetLineCap(System.Drawing.Drawing2D.LineCap.RoundAnchor,System.Drawing.Drawing2D.LineCap.ArrowAnchor,System.Drawing.Drawing2D.DashCap.Flat);
    Graphics g=this.CreateGraphics();
    g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    g.DrawLine (p,p1,p2);
    g.Dispose ();
    p.Dispose();
    } private void S1(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    p1.X=e.X;
    p1.Y=e.Y;

    } private void S2(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    p2.X=e.X;
    p2.Y=e.Y;
    ddl();
    }
    }
    }