📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace Exam7_1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private Graphics g;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
g=this.CreateGraphics();
//
// 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()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(296, 189);
this.Name = "Form1";
this.Text = "随机画圆";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
Thread th1=new Thread(new ThreadStart(run));
th1.Start();
}
void draw()
{
int x,y,w,h,ww;
Color c;
w=this.Width; //取出画面大小
h=this.Height;
Random ra=new Random();
x=ra.Next(w)+1; //计算随机位置
y=ra.Next(h)+1;
ww=ra.Next((h>w?h:w)/3)+20;
c=Color.FromArgb(ra.Next(256),ra.Next(256),ra.Next(256));
SolidBrush brush=new SolidBrush(c);
g.FillEllipse(brush,x,y,ww,ww); //画圆
}
public void run()
{ //方法中是线程执行的内容
while(true)
{
draw();
Thread.Sleep(500); //睡眠半秒,即每隔半秒执行一次
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -