using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace x3
{
public partial class Form1 : Form {
public static void Main()
{
Application.Run(new Form1());
} public Form1()
{
//InitializeComponent();
Text = "hello:";
Timer timer=new Timer() ;
timer.Interval =10;
timer.Tick +=new EventHandler (TimerOnTick);
timer.Start();
}
void TimerOnTick(object obj,EventArgs ea)
{
Random rand= new Random ();
int x1=rand.Next(ClientSize.Width +100);
int x2=rand.Next(ClientSize.Width -100);
int y1=rand.Next(ClientSize.Height-200 );
int y2=rand.Next(ClientSize.Height-200);
Color color =Color.FromArgb(rand.Next(256),
rand.Next(256),
rand.Next(256));
Graphics grfx=CreateGraphics ();
grfx.FillRectangle (new SolidBrush (color),Math .Min (x1,x2),Math.Min(y1,y2),
Math.Abs(x2-x1),Math.Abs(y2-y1));
grfx.Dispose ();
}
}
}
如何让timer timer 停止运行,
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace x3
{
public partial class Form1 : Form {
public static void Main()
{
Application.Run(new Form1());
} public Form1()
{
//InitializeComponent();
Text = "hello:";
Timer timer=new Timer() ;
timer.Interval =10;
timer.Tick +=new EventHandler (TimerOnTick);
timer.Start();
}
void TimerOnTick(object obj,EventArgs ea)
{
Random rand= new Random ();
int x1=rand.Next(ClientSize.Width +100);
int x2=rand.Next(ClientSize.Width -100);
int y1=rand.Next(ClientSize.Height-200 );
int y2=rand.Next(ClientSize.Height-200);
Color color =Color.FromArgb(rand.Next(256),
rand.Next(256),
rand.Next(256));
Graphics grfx=CreateGraphics ();
grfx.FillRectangle (new SolidBrush (color),Math .Min (x1,x2),Math.Min(y1,y2),
Math.Abs(x2-x1),Math.Abs(y2-y1));
grfx.Dispose ();
}
}
}
如何让timer timer 停止运行,
解决方案 »
- C#winform里怎么实现放大图片?
- 如何获得局域网计算机磁盘信息
- Request.UrlReferrer 乱码
- 急需:如何把任意类型的文件添加到access数据库ole类型字段?另外还需要读取出来的代码,谢谢
- 一个条件限制的问题,大家帮忙进来帮忙!分不够再加
- !~!!!急请版主和高手帮助!!一个asp.net程序在服务器上,我从本机IE访问运行可出现如下错误(将对象引用设置到对象的实例.......),详
- 以下是读取网络图片数据流代码,我想读取本地的图片数据流,如何改?谢谢!
- 由一个指定6位数产生的乱序6位数
- 如何实现类似JScript中eval()的功能?
- @@@有谁要Thinking C#?免费发送@@@
- .bat文件中的问题
- 数据插入问题,什么是变异数 ?十分着急,这是个什么概念?
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button btnStop;
Timer timer;
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.components = new System.ComponentModel.Container();
this.btnStop = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(112, 136);
this.btnStop.Name = "btnStop";
this.btnStop.TabIndex = 0;
this.btnStop.Text = "结束";
this.btnStop.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(112, 72);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnStop);
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)
{
Text = "hello:";
timer=new Timer() ;
timer.Interval =10;
timer.Tick +=new EventHandler (TimerOnTick);
timer.Start(); }
void TimerOnTick(object obj,EventArgs ea)
{
Random rand= new Random ();
int x1=rand.Next(ClientSize.Width +100);
int x2=rand.Next(ClientSize.Width -100);
int y1=rand.Next(ClientSize.Height-200 );
int y2=rand.Next(ClientSize.Height-200);
Color color =Color.FromArgb(rand.Next(256),
rand.Next(256),
rand.Next(256));
Graphics grfx=CreateGraphics ();
grfx.FillRectangle (new SolidBrush (color),Math .Min (x1,x2),Math.Min(y1,y2),
Math.Abs(x2-x1),Math.Abs(y2-y1));
grfx.Dispose ();
} private void button1_Click(object sender, System.EventArgs e)
{
timer.Stop();
} }
}
timer.enable = false;
timer1.Stop();System.Timers.Timer timer2;
timer2.Stop();System.Threading.Timer timer3;
timer3.Change(-1,-1); //不知道是不是必需
timer3.Dispose();