国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

使用C#編程實(shí)現(xiàn)圓的移動(dòng)

2023-05-16 12:36:04
字體:
供稿:網(wǎng)友

本例實(shí)現(xiàn)了編程移動(dòng)一個(gè)圓:

using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
public class AnimateFace : Form {
  private int x = 10, y = 10;
  private int width = 200, height = 200;

  private Button suspend = new Button();
  private Button resume = new Button();
  private Button abort = new Button();
  private Thread t;

  public AnimateFace() {
    BackColor = Color.White;
    abort.Text = "Abort";
    suspend.Text = "Suspend";
    resume.Text = "Resume";
 
    Controls.Add(suspend);
    Controls.Add(resume);
    Controls.Add(abort);

    int w = 20;
    suspend.Location = new Point(w, 240);
    resume.Location = new Point(w += 10 + suspend.Width, 240);     
    abort.Location = new Point(w += 10 + resume.Width, 240);

    abort.Click += new EventHandler(Abort_Click);
    suspend.Click += new EventHandler(Suspend_Click);
    resume.Click += new EventHandler(Resume_Click);

    t = new Thread(new ThreadStart(Run));
    t.Start();
  }
  protected void Abort_Click(object sender, EventArgs e) {
    t.Abort();
  }
  protected void Suspend_Click(object sender, EventArgs e) {
    t.Suspend();
  }
  protected void Resume_Click(object sender, EventArgs e) {
    t.Resume();
  }
  protected override void OnPaintPaintEventArgs e )   {
    Graphics g = e.Graphics;
    Pen green = new Pen(Color.Green, 3);  
    Brush red = new SolidBrush(Color.Red);
    g.DrawEllipse(green, x, y, width, height);
    base.OnPaint(e);
  }
  public void Run() {
    int dx=9, dy=9;
    while (true) {
      for (int i = 0; i < 30; i++) { 
        x += dx; 
        y += dy; 
        width -= dx; 
        height -= dy;
        Invalidate();
        Thread.Sleep(30);
      }
      dx = -dx; dy = -dy; 
    }
  }
  public static void Main( ) {
    Application.Run(new AnimateFace());
  }        
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平陆县| 宝丰县| 漠河县| 周宁县| 贵德县| 洪江市| 江都市| 甘孜| 绥阳县| 华宁县| 莱阳市| 桐庐县| 黄龙县| 耒阳市| 临潭县| 六安市| 莱州市| 锡林郭勒盟| 黑龙江省| 蓝田县| 南充市| 水富县| 肃宁县| 夹江县| 嘉义县| 茌平县| 疏附县| 新营市| 英吉沙县| 九江市| 禹州市| 象州县| 江门市| 德保县| 井冈山市| 隆化县| 彭州市| 绥棱县| 建水县| 宁陕县| 宁陕县|