| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1392 人关注过本帖
标题:[求助]走过路过千万不要错过
只看楼主 加入收藏
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
1,可以

2,可以 只是執行的情況下你沒辦法動 而且每次執行間隔時間大了

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-23 10:52
tanghuawei
Rank: 4
来 自:美丽的湖南
等 级:业余侠客
威 望:3
帖 子:531
专家分:220
注 册:2006-3-16
收藏
得分:0 
郁闷,搞不出来,能不能帮我改下咯,感激不尽!

汽车尾气检测网络系统QQ:357766186__MSN:MSNTHW19850316@
2006-08-23 11:09
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
[CODE]

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace waTest
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;

private Thread m_thread;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
if(m_thread.IsAlive)
m_thread.Abort();
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnClose = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.btnStart = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(8, 104);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 6;
this.btnClose.Text = "Close";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(8, 56);
this.btnStop.Name = "btnStop";
this.btnStop.TabIndex = 7;
this.btnStop.Text = "Stop";
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(8, 8);
this.btnStart.Name = "btnStart";
this.btnStart.TabIndex = 5;
this.btnStart.Text = "Start";
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// timer1
//
//this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(520, 477);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnStart);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void StartDrawing()
{
while(true)
{
int width = 10;
int high = 10;

Graphics g = this.CreateGraphics();
System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Gray, Color.Gray, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
System.Drawing.Drawing2D.LinearGradientBrush myBrush2 = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Red, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.Vertical);

for(int y = 10;y<470;y=y+10)
{
for(int x = 170; x<310;x = x+10)
{
g.FillEllipse(myBrush,x,y,width,high);
g.FillEllipse(myBrush,y,x,width,high);
}
}
System.Threading.Thread.CurrentThread.Join(1000);

for(int y = 460;y>=10;y=y-10)
{
for(int x =300; x>160;x = x-10)
{
g.FillEllipse(myBrush2,x,y,width,high);
g.FillEllipse(myBrush2,y,x,width,high);
}
}
System.Threading.Thread.CurrentThread.Join(1000);
}
}

private void btnStart_Click(object sender, System.EventArgs e)
{
//this.timer1.Interval=5000;
//this.timer1.Start();
m_thread=new Thread(new ThreadStart(StartDrawing));
m_thread.Start();

}

private void btnStop_Click(object sender, System.EventArgs e)
{
this.timer1.Stop();
m_thread.Abort();
}

private void btnClose_Click(object sender, System.EventArgs e)
{
Close();
}
}
}

[/CODE]

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-23 11:18
小海龟
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1068
专家分:4
注 册:2006-8-1
收藏
得分:0 
把你源代码打包传上去啊。

[bc09] 犯强汉者,虽远比诛!
2006-08-23 11:18
tanghuawei
Rank: 4
来 自:美丽的湖南
等 级:业余侠客
威 望:3
帖 子:531
专家分:220
注 册:2006-3-16
收藏
得分:0 
多谢chenjin145。问题解决了!

汽车尾气检测网络系统QQ:357766186__MSN:MSNTHW19850316@
2006-08-23 11:43
tanghuawei
Rank: 4
来 自:美丽的湖南
等 级:业余侠客
威 望:3
帖 子:531
专家分:220
注 册:2006-3-16
收藏
得分:0 
但是还有点小小的问题,当点Stop的时候,它会有段时间停留。

汽车尾气检测网络系统QQ:357766186__MSN:MSNTHW19850316@
2006-08-23 11:44
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 

改為Suspend線程
要判斷線程狀態
開始改為Resume 線程


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-23 12:01
tanghuawei
Rank: 4
来 自:美丽的湖南
等 级:业余侠客
威 望:3
帖 子:531
专家分:220
注 册:2006-3-16
收藏
得分:0 

不好意思,要怎么改哦?麻烦了!


汽车尾气检测网络系统QQ:357766186__MSN:MSNTHW19850316@
2006-08-23 13:08
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
[CODE]

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace waTest
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;

private Thread m_thread;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(m_thread!=null)
{
//if(m_thread.ThreadState==ThreadState.SuspendRequested)
m_thread.Resume();
m_thread.Abort();
}
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnClose = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.btnStart = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(7, 111);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(62, 25);
this.btnClose.TabIndex = 6;
this.btnClose.Text = "Close";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(7, 60);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(62, 25);
this.btnStop.TabIndex = 7;
this.btnStop.Text = "Stop";
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(7, 9);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(62, 24);
this.btnStart.TabIndex = 5;
this.btnStart.Text = "Start";
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(433, 511);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnStart);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void StartDrawing()
{
while(true)
{
int width = 10;
int high = 10;

Graphics g = this.CreateGraphics();
System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Gray, Color.Gray, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
System.Drawing.Drawing2D.LinearGradientBrush myBrush2 = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Red, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.Vertical);

for(int y = 10;y<470;y=y+10)
{
for(int x = 170; x<310;x = x+10)
{
g.FillEllipse(myBrush,x,y,width,high);
g.FillEllipse(myBrush,y,x,width,high);
}
}
//System.Threading.Thread.CurrentThread.Join(1000);
Thread.Sleep(1000);

for(int y = 460;y>=10;y=y-10)
{
for(int x =300; x>160;x = x-10)
{
g.FillEllipse(myBrush2,x,y,width,high);
g.FillEllipse(myBrush2,y,x,width,high);
}
}
//System.Threading.Thread.CurrentThread.Join(1000);
Thread.Sleep(1000);
}
}

private void btnStart_Click(object sender, System.EventArgs e)
{
if(m_thread==null)
{
m_thread=new Thread(new ThreadStart(StartDrawing));
m_thread.Start();
}
else
{
m_thread.Resume();
}

}

private void btnStop_Click(object sender, System.EventArgs e)
{
m_thread.Suspend();
MessageBox.Show(m_thread.ThreadState.ToString());

}

private void btnClose_Click(object sender, System.EventArgs e)
{
Close();
}

}
}

[/CODE]

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-23 14:10
zhanghong3077
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-8-23
收藏
得分:0 

做事要认真哦
2006-08-23 17:16
快速回复:[求助]走过路过千万不要错过
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024076 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved