| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:谁来教教我?
只看楼主 加入收藏
阳光下的麦田
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-11-29
收藏
 问题点数:0 回复次数:2 
谁来教教我?

今天在写一个使用Timer的关于Button的程序,碰到了一个小问题,我搞了一个下午,到现在还没弄出来类.
是这样的:我的程序里面有个button1,我想让程序运行后用定时器实现button1的5秒钟的呈灰色状态;5秒
后button1由灰色状态变为可用.就向某些论坛的账号申请页面,里面用户声明页面的"同意"按钮一样,在X
秒后自动变为可用的功能.

希望各位大人能帮小弟解决一下,在下不胜感激!
就是在OnTimedEvent()里面我想写this.button1.text = this.intTimer.ToString();可是vs说
"关键字this在静态属性,静态方法或静态字段初始值设定项中无效",怎么解决啊??
我的代码在下面:

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 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-12-01 23:14
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 

public static void OnTimedEvent

关键是红色的那个,至于为什么,你自己先想想,语法基础都没看熟。

[此贴子已经被作者于2005-12-2 15:52:59编辑过]

2005-12-02 15:49
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
建议楼主在学习可视化之前看一本语法书打好基础。
2005-12-02 15:54
快速回复:谁来教教我?
数据加载中...
 
   



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

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