请教一个有关form的问题,谢谢。

asgard 2004-08-20 10:01:52
程序走到某一步要调用一个form,这个form中的进度条一遍又一遍的从头到尾的走,速度没有限定,差不多就行,另外form中lable上的汉字一闪一闪的,就是一会可见一会不可见。这样状态保持到某个处理结束,这个处理函数内部比较复杂。

不知道该怎么实现!
有些朋友说要用timer和多线程,这两个我都没有用过,能不能给一点简单的示例代码,谢谢!
...全文
106 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
asgard 2004-08-20
  • 打赏
  • 举报
回复
还有那个汉字闪烁的时间间隔在哪里控制?
asgard 2004-08-20
  • 打赏
  • 举报
回复
to qimini(循序渐进)
请问在程序里面是不是这样去启动这个form:

frmWaiting fw = new frmWaiting ();
fw.show();

应为我已经有一个form启动了,不能再Applicaiton.run(fw);
应该怎么办?
yingshis 2004-08-20
  • 打赏
  • 举报
回复
帮你up
asgard 2004-08-20
  • 打赏
  • 举报
回复
自己up
qimini 2004-08-20
  • 打赏
  • 举报
回复
下面是源代码:


/// <summary>
/// Summary description for frmWaiting.
/// </summary>
public class frmWaiting : System.Windows.Forms.Form
{
private int iCount = 100000;
private int iStart = 0;

private System.Windows.Forms.Panel panFill;
private System.Windows.Forms.Label lblMessage;
private System.Windows.Forms.Timer timProcess;
private System.Windows.Forms.ProgressBar pgbProcess;
private System.ComponentModel.IContainer components;

public frmWaiting()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.panFill = new System.Windows.Forms.Panel();
this.pgbProcess = new System.Windows.Forms.ProgressBar();
this.lblMessage = new System.Windows.Forms.Label();
this.timProcess = new System.Windows.Forms.Timer(this.components);
this.panFill.SuspendLayout();
this.SuspendLayout();
//
// panFill
//
this.panFill.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panFill.Controls.Add(this.pgbProcess);
this.panFill.Controls.Add(this.lblMessage);
this.panFill.Dock = System.Windows.Forms.DockStyle.Fill;
this.panFill.Location = new System.Drawing.Point(0, 0);
this.panFill.Name = "panFill";
this.panFill.Size = new System.Drawing.Size(672, 72);
this.panFill.TabIndex = 0;
//
// pgbProcess
//
this.pgbProcess.Location = new System.Drawing.Point(0, 32);
this.pgbProcess.Name = "pgbProcess";
this.pgbProcess.Size = new System.Drawing.Size(656, 23);
this.pgbProcess.TabIndex = 1;
//
// lblMessage
//
this.lblMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lblMessage.Location = new System.Drawing.Point(0, 0);
this.lblMessage.Name = "lblMessage";
this.lblMessage.Size = new System.Drawing.Size(656, 23);
this.lblMessage.TabIndex = 0;
this.lblMessage.Text = "正在组织数据,请稍候...";
this.lblMessage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// timProcess
//
this.timProcess.Interval = 10;
this.timProcess.Tick += new System.EventHandler(this.timProcess_Tick);
//
// frmWaiting
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(672, 72);
this.Controls.Add(this.panFill);
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "frmWaiting";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "frmWaiting";
this.Load += new System.EventHandler(this.frmWaiting_Load);
this.panFill.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

private void timProcess_Tick(object sender, System.EventArgs e)
{
if (this.lblMessage.Visible == true)
{
this.lblMessage.Visible = false;
}
else
{
this.lblMessage.Visible = true;
this.lblMessage.Text = this.lblMessage.Text;
}

if (iStart == iCount)
{
this.timProcess.Enabled = false;
this.Close();
}
else
{
this.lblMessage.Visible = true;

if (this.pgbProcess.Value == 100)
{
this.pgbProcess.Value = 0;
}

this.pgbProcess.Value += 5;

iStart += 100;
}
}

private void frmWaiting_Load(object sender, System.EventArgs e)
{
this.timProcess.Enabled = true;
}

}
vzxq 2004-08-20
  • 打赏
  • 举报
回复
UP
Samen168 2004-08-20
  • 打赏
  • 举报
回复
//
// progressBar1
//
this.progressBar1.AccessibleDescription = resources.GetString("progressBar1.AccessibleDescription");
this.progressBar1.AccessibleName = resources.GetString("progressBar1.AccessibleName");
this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("progressBar1.Anchor")));
this.progressBar1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("progressBar1.BackgroundImage")));
this.progressBar1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("progressBar1.Dock")));
this.progressBar1.Enabled = ((bool)(resources.GetObject("progressBar1.Enabled")));
this.progressBar1.Font = ((System.Drawing.Font)(resources.GetObject("progressBar1.Font")));
this.progressBar1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("progressBar1.ImeMode")));
this.progressBar1.Location = ((System.Drawing.Point)(resources.GetObject("progressBar1.Location")));
this.progressBar1.Name = "progressBar1";
this.progressBar1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("progressBar1.RightToLeft")));
this.progressBar1.Size = ((System.Drawing.Size)(resources.GetObject("progressBar1.Size")));
this.progressBar1.Step = 1;
this.progressBar1.TabIndex = ((int)(resources.GetObject("progressBar1.TabIndex")));
this.progressBar1.Text = resources.GetString("progressBar1.Text");
this.progressBar1.Visible = ((bool)(resources.GetObject("progressBar1.Visible")));
//
// lblName
//
this.lblName.AccessibleDescription = resources.GetString("lblName.AccessibleDescription");
this.lblName.AccessibleName = resources.GetString("lblName.AccessibleName");
this.lblName.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("lblName.Anchor")));
this.lblName.AutoSize = ((bool)(resources.GetObject("lblName.AutoSize")));
this.lblName.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("lblName.Dock")));
this.lblName.Enabled = ((bool)(resources.GetObject("lblName.Enabled")));
this.lblName.Font = ((System.Drawing.Font)(resources.GetObject("lblName.Font")));
this.lblName.Image = ((System.Drawing.Image)(resources.GetObject("lblName.Image")));
this.lblName.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("lblName.ImageAlign")));
this.lblName.ImageIndex = ((int)(resources.GetObject("lblName.ImageIndex")));
this.lblName.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("lblName.ImeMode")));
this.lblName.Location = ((System.Drawing.Point)(resources.GetObject("lblName.Location")));
this.lblName.Name = "lblName";
this.lblName.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("lblName.RightToLeft")));
this.lblName.Size = ((System.Drawing.Size)(resources.GetObject("lblName.Size")));
this.lblName.TabIndex = ((int)(resources.GetObject("lblName.TabIndex")));
this.lblName.Text = resources.GetString("lblName.Text");
this.lblName.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("lblName.TextAlign")));
this.lblName.Visible = ((bool)(resources.GetObject("lblName.Visible")));
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// ProcessControl
//
this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
this.AccessibleName = resources.GetString("$this.AccessibleName");
this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.Controls.Add(this.panel1);
this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
this.Name = "ProcessControl";
this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
this.Size = ((System.Drawing.Size)(resources.GetObject("$this.Size")));
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

private void timer1_Tick(object sender, System.EventArgs e)
{
try
{
if(this.progressBar1.Value==this.progressBar1.Maximum)
this.progressBar1.Value=0;
else
this.progressBar1.Value+=10;
Application.DoEvents();
}
catch(Exception er)
{
MessageBox.Show(er.ToString());
}
}

public override string Text
{
get
{
return this.lblName.Text;
}
set
{
this.lblName.Text = value;
}
}

}
}
Samen168 2004-08-20
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using LongWin.EnterpriseObjects;

namespace ApplicationBrowser
{
/// <summary>
/// ProcessControl 的摘要说明。
/// </summary>
public class ProcessControl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label lblName;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;

public ProcessControl()
{
try
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();

// TODO: 在 InitializeComponent 调用后添加任何初始化
this.progressBar1.Value=(DateTime.Now.Millisecond / 100) *10;
}
catch(Exception er)
{
MessageBox.Show(er.ToString());
}
}

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

#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ProcessControl));
this.panel1 = new System.Windows.Forms.Panel();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.lblName = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.AccessibleDescription = resources.GetString("panel1.AccessibleDescription");
this.panel1.AccessibleName = resources.GetString("panel1.AccessibleName");
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("panel1.Anchor")));
this.panel1.AutoScroll = ((bool)(resources.GetObject("panel1.AutoScroll")));
this.panel1.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("panel1.AutoScrollMargin")));
this.panel1.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("panel1.AutoScrollMinSize")));
this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));
this.panel1.Controls.Add(this.progressBar1);
this.panel1.Controls.Add(this.lblName);
this.panel1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("panel1.Dock")));
this.panel1.Enabled = ((bool)(resources.GetObject("panel1.Enabled")));
this.panel1.Font = ((System.Drawing.Font)(resources.GetObject("panel1.Font")));
this.panel1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("panel1.ImeMode")));
this.panel1.Location = ((System.Drawing.Point)(resources.GetObject("panel1.Location")));
this.panel1.Name = "panel1";
this.panel1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("panel1.RightToLeft")));
this.panel1.Size = ((System.Drawing.Size)(resources.GetObject("panel1.Size")));
this.panel1.TabIndex = ((int)(resources.GetObject("panel1.TabIndex")));
this.panel1.Text = resources.GetString("panel1.Text");
this.panel1.Visible = ((bool)(resources.GetObject("panel1.Visible")));
qimini 2004-08-20
  • 打赏
  • 举报
回复
1、是
2、我是放在一个Timer里来控制的,如果你绝得有必要可以放到另外的Timer里控制
private void timProcess_Tick(object sender, System.EventArgs e)
{
if (this.lblMessage.Visible == true)
{
this.lblMessage.Visible = false;
}
else
{
this.lblMessage.Visible = true;
this.lblMessage.Text = this.lblMessage.Text;
}

if (iStart == iCount)
{
this.timProcess.Enabled = false;
this.Close();
}
else
{
//这一行删除this.lblMessage.Visible = true;

if (this.pgbProcess.Value == 100)
{
this.pgbProcess.Value = 0;
}

this.pgbProcess.Value += 5;

iStart += 100;
}
}
3、这个只是一个简单的例子~~~仅供参考


希望能对你有所帮助~~~

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧