| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 548 人关注过本帖
标题:那位大姐能帮我解决一下个人问题啊:) 我是新手,今天在弄C#的时候,碰到了一 ...
只看楼主 加入收藏
阳光下的麦田
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-11-29
收藏
 问题点数:0 回复次数:1 
那位大姐能帮我解决一下个人问题啊:) 我是新手,今天在弄C#的时候,碰到了一个小问题

今天在写一个使用Timer的关于Button的程序,碰到了一个小问题,我搞了一个下午,到现在还没弄出来类.

是这样的:我的程序里面有个button1,我想让程序运行后用定时器实现button1的5秒钟的呈灰色状态;5秒

后button1由灰色状态变为可用.就向某些论坛的账号申请页面,里面用户声明页面的"同意"按钮一样,在X

秒后自动变为可用的功能.

希望各位大人能帮小弟解决一下,在下不胜感激!

就是在哪个OntimedEvent()里面不能使用本类里面定义的变量和函数啊??????
我的代码在下面:

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Timers;

namespace UseTimer

{

/// <summary>

/// Form1 的摘要说明。

/// </summary>

public class MyTimer : System.Windows.Forms.Form

{

private System.Windows.Forms.Button button1;

private System.ComponentModel.IContainer components;

private System.Timers.Timer aTimer;

private static int intTimer = 5;

private static string buttonText ;

//private void change();

public MyTimer()

{

//

// 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.button1 = new System.Windows.Forms.Button();

this.aTimer = new System.Timers.Timer();

((System.ComponentModel.ISupportInitialize)(this.aTimer)).BeginInit();

this.SuspendLayout();

//

// button1

//

this .button1 .Location = new System.Drawing.Point(96, 96);

this .button1 .Name = "button1";

this .button1 .TabIndex = 1;

this .button1 .Text = "确定(5)";

//

// aTimer

//

this.aTimer.Enabled = true;

this.aTimer.Interval = 1000;

this.aTimer.SynchronizingObject = this;

//

// MyTimer

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(292, 268);

this.Controls.Add(this.button1 );

this.Name = "MyTimer";

this.Text = "MyTimer";

this.Load += new System.EventHandler(this.MyTimer_Load);

((System.ComponentModel.ISupportInitialize)(this.aTimer)).EndInit();

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new MyTimer ());

}

private void MyTimer_Load(object sender, System.EventArgs e)

{

this.button1 .Enabled = false;

}

private void timer1_Tick(object sender, System.EventArgs e)

{

}

private static void OnTimedEvent(object source, ElapsedEventArgs e)

{

if ( MyTimer.intTimer >0)

{

MyTimer.buttonText = MyTimer.intTimer .ToString ();

MyTimer.intTimer --;

this.button1.Text ="确定(" + buttonText + ")";

}

else

{

this.button1.Enabled = true;

this.button1.Text = "确定";

}

}

}

}

[此贴子已经被作者于2005-11-30 22:27:42编辑过]

搜索更多相关主题的帖子: 大姐 left align 
2005-11-30 22:06
g2thomas
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-11-27
收藏
得分:0 

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

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;

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

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <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.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// button1
//
this.button1.Enabled = false;
this.button1.Location = new System.Drawing.Point(8, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(632, 200);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 5000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(648, 502);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void timer1_Tick(object sender, System.EventArgs e)
{
this.button1.Enabled = true;
this.timer1.Enabled = false;
}
}
}


2005-12-01 08:13
快速回复:那位大姐能帮我解决一下个人问题啊:) 我是新手,今天在弄C#的时候,碰到 ...
数据加载中...
 
   



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

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