想让一个label在form窗体上间隔一段时间闪烁一次隔一段时间在闪烁一次 想让一个label在form窗体上间隔一段时间闪烁一次隔一段时间在闪烁一次间隔时间成1,3,5....2n-1,递增的;不要用timer控件,想用多线程using System.Threading不知道如何操作.大家帮看下. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for循环if 1,3,5....2n-1Sleep 时间把label透明度设为0否则 100 创建一个线程,在线程类里面定义一个label控件,在界面上拖一个label控件,ClassStartThread startThread = new ClassStartThread( this.label1); Thread st = new Thread(new ThreadStart(startThread.StartThread)); tUdpThread.IsBackground = true; tUdpThread.Start();[code=C#] class ClassStartThread { private int tm=0; private int lt=0; private Label label1; public ClassStartUdpThread(Label label2) { this.label1 = label2; tm = DateTime.Now.Second; tm += DateTime.Now.Minute * 60; tm += DateTime.Now.Hour * 3600; } public void StartThread() { for(int i=0;;i++) { lt= DateTime.Now.Second; lt += DateTime.Now.Minute * 60; lt += DateTime.Now.Hour * 3600; if((lt-tm)==((2*i)-1)) { this.label1.Enabled=false; } Thread.Sleep(10); this.label1.Enabled=true; } } }[/code]大致就这样,随便写的, 也不知道有没有错误,有错误,请楼下的指正!在此先谢过了! 闪烁?可见->不可见->可见->..... 这样?那加个timer就搞定了要想显眼,还是定时改变label的字体颜色好些 quartz调度组件可完成你要的效果 为什么不用timer控件,以下的代码,timer1用于显示闪的效果,timer2用于控制你所谓的递增间隔的时间闪烁的控制,更简单更容易理解Form1.Designer.csnamespace WindowsApplication5{ partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.label1 = new System.Windows.Forms.Label(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer2 = new System.Windows.Forms.Timer(this.components); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label1.Location = new System.Drawing.Point(58, 53); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(71, 29); this.label1.TabIndex = 0; this.label1.Text = "我闪"; // // timer1 // this.timer1.Interval = 200; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // timer2 // this.timer2.Interval = 200; this.timer2.Tick += new System.EventHandler(this.timer2_Tick); // // button1 // this.button1.Location = new System.Drawing.Point(270, 78); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(386, 606); this.Controls.Add(this.button1); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Timer timer2; private System.Windows.Forms.Button button1; }}Form1.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication5{ public partial class Form1 : Form { private int nN = 0, nCount = 0; public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { label1.Visible = true; timer1.Enabled = false; } private void button1_Click(object sender, EventArgs e) { timer2.Enabled = true; } private void timer2_Tick(object sender, EventArgs e) { if (nCount >= 2 * nN - 1) { nCount = 0; nN++; label1.Visible = false; timer1.Enabled = true; } nCount++; } }} beckfun gogogo 非常感谢你们的热心帮助!!问题基本解决了啊!! 给多个picturebox循环赋值 有没有不要dll文件就可以在Winform里添加音乐的方法 问个多线程更新界面的问题 有关于C#的一段语句,应该如何解读? 问题描述:子窗体调用主窗体的事件? 关于页面跳转的问题,急,在线等待... 急问C#如何绘制透明位图? ??? C# 安装部署后运行程序提示错误 如何用水晶报表显示程序运行中产生的DataTable里面的数据? 怎么把多个文件(如BMP,JPEJ,EXCEL)存到一个文件当中。 关于静态变量初始化的问题
if 1,3,5....2n-1
Sleep 时间
把label透明度设为0
否则 100
ClassStartThread startThread = new ClassStartThread( this.label1);
Thread st = new Thread(new ThreadStart(startThread.StartThread));
tUdpThread.IsBackground = true;
tUdpThread.Start();
[code=C#]
class ClassStartThread
{
private int tm=0;
private int lt=0;
private Label label1;
public ClassStartUdpThread(Label label2)
{
this.label1 = label2;
tm = DateTime.Now.Second;
tm += DateTime.Now.Minute * 60;
tm += DateTime.Now.Hour * 3600;
}
public void StartThread()
{
for(int i=0;;i++)
{
lt= DateTime.Now.Second;
lt += DateTime.Now.Minute * 60;
lt += DateTime.Now.Hour * 3600;
if((lt-tm)==((2*i)-1))
{
this.label1.Enabled=false;
}
Thread.Sleep(10);
this.label1.Enabled=true;
}
}
}[/code]大致就这样,随便写的, 也不知道有没有错误,有错误,请楼下的指正!在此先谢过了!
Form1.Designer.cs
namespace WindowsApplication5
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(58, 53);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 29);
this.label1.TabIndex = 0;
this.label1.Text = "我闪";
//
// timer1
//
this.timer1.Interval = 200;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// timer2
//
this.timer2.Interval = 200;
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
//
// button1
//
this.button1.Location = new System.Drawing.Point(270, 78);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(386, 606);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Button button1;
}
}Form1.csusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication5
{
public partial class Form1 : Form
{
private int nN = 0, nCount = 0;
public Form1()
{
InitializeComponent();
} private void timer1_Tick(object sender, EventArgs e)
{
label1.Visible = true;
timer1.Enabled = false;
} private void button1_Click(object sender, EventArgs e)
{
timer2.Enabled = true;
} private void timer2_Tick(object sender, EventArgs e)
{
if (nCount >= 2 * nN - 1)
{
nCount = 0;
nN++;
label1.Visible = false;
timer1.Enabled = true;
}
nCount++;
}
}
}
gogogo
非常感谢你们的热心帮助!!问题基本解决了啊!!