小弟最近在做一个课件,我想在当一个控件激发click事件时能够在另一个控件上画出某些图形,
因为要持久化图形的显示,所以我把绘图的逻辑放在了该控件的onPaint方法中。
    有关图形的位置和区域我都可以搞定,这样,虽然图形可以画出来,但看不到绘制的过程,我希望能够看到绘图的过程。比如:当一个按钮的click事件激发时,我希望在一个UserControl控件上的某个区域“慢慢地”(即有个时间段)画条直线,而在另外一个区域上也“慢慢地”将一个正方形图形从一个位置移动到另一个位置。    不知道大家能否理解我的意思,小弟现在就10分了,虽然少了点,但这是我最后的一点家当啦,谢谢。

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;using System.Drawing.Imaging;namespace test2
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; 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 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(532, 72);
    this.button1.Name = "button1";
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(636, 445);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {

    } private void button1_Click(object sender, System.EventArgs e)
    {
    System.Threading.Thread th=new System.Threading.Thread(new System.Threading.ThreadStart(StartDraw));
    th.Start();
    //dataSet11.WriteXml(@"c:\a.xml",XmlWriteMode.WriteSchema);
    }
    private void StartDraw()
    {
    //当然这里的画法需要你自己的算法来计算,这里只是画个最简单的矩形
    //而且应该是在onPaint事件中,这里就不做处理了
    Draw(new Point(0,0),new Point(0,100));
    Draw(new Point(0,100),new Point(100,100));
    Draw(new Point(100,100),new Point(100,0));
    Draw(new Point(100,0),new Point(0,0));
    }
    private void Draw(Point p1,Point p2)
    {
    Graphics g=this.CreateGraphics();
    g.DrawLine(Pens.Blue,p1,p2);
    System.Threading.Thread.Sleep(500);
    }

    }
    }