主题:[讨论]关于启动界面时用的timer控件问题[求助]
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
运行后错误提示为上句中的:“System.Windows.Forms.Timer”并不包含“Elapsed”的定义。
这就很郁闷了,如果系统自己没定义timer的这个Elapsed事件的话偶该怎么办??
偶用的是vs.net2005..生成的主要3段:
From1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace qidongjiemian
{
public partial class start : Form
{
public start()
{
InitializeComponent();
}
private void Form1_Load(object sender,EventArgs e)
{
}
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.Opacity < 1)
{
this.Opacity += 0.01;
progressBar1.Value = (int)(this.Opacity * 100);
}
else
{
timer1.Enabled = false; Dispose(false); (new MainWindow()).Show();
}
}
}
}
Form1.Designer.cs:
namespace qidongjiemian
{
partial class start
{
/// <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();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(start));
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.progressBar1.Location = new System.Drawing.Point(0, 419);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(557, 12);
this.progressBar1.TabIndex = 0;
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 50;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);/*就是这句出了错....*/
//
// start
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(557, 431);
this.Controls.Add(this.progressBar1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MinimizeBox = false;
this.Name = "start";
this.Opacity = 0;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.TopMost = true;
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Timer timer1;
}
}
Program.cs:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace qidongjiemian
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new start());
}
}
}
--------------------
至于新添加的MainWindow.cs就不用写出来了....
偶的错误主要出在 Form1.Desinger.cs 中的那句中.....
希望各位大大们能给我提示,帮助偶解决这个问题...谢谢了.....
运行后错误提示为上句中的:“System.Windows.Forms.Timer”并不包含“Elapsed”的定义。
这就很郁闷了,如果系统自己没定义timer的这个Elapsed事件的话偶该怎么办??
偶用的是vs.net2005..生成的主要3段:
From1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace qidongjiemian
{
public partial class start : Form
{
public start()
{
InitializeComponent();
}
private void Form1_Load(object sender,EventArgs e)
{
}
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.Opacity < 1)
{
this.Opacity += 0.01;
progressBar1.Value = (int)(this.Opacity * 100);
}
else
{
timer1.Enabled = false; Dispose(false); (new MainWindow()).Show();
}
}
}
}
Form1.Designer.cs:
namespace qidongjiemian
{
partial class start
{
/// <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();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(start));
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.progressBar1.Location = new System.Drawing.Point(0, 419);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(557, 12);
this.progressBar1.TabIndex = 0;
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 50;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);/*就是这句出了错....*/
//
// start
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(557, 431);
this.Controls.Add(this.progressBar1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MinimizeBox = false;
this.Name = "start";
this.Opacity = 0;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.TopMost = true;
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Timer timer1;
}
}
Program.cs:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace qidongjiemian
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new start());
}
}
}
--------------------
至于新添加的MainWindow.cs就不用写出来了....
偶的错误主要出在 Form1.Desinger.cs 中的那句中.....
希望各位大大们能给我提示,帮助偶解决这个问题...谢谢了.....