一个让我想了好久也没有搞定的问题!(按钮方面的) 类中保存一个布尔字段。bool runEvent;在按钮的点击处理函数中。。runEvent ^= true; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 同意楼上的方法在类中保存一个静态的bool型变量 按钮控件有Tag属性,就是干这个用的,你点击的时候纪录一下就行了 if(button1.Tag==true){..........//执行这些事件button1.Tag=false;}else{button1.Tag=true;} 在类中保存一个静态的bool型变量???如何声明一静态变量? if(button1.Tag==true){..........//执行这些事件button1.Tag=false;}else{button1.Tag=true;}这种做法不行呀.错误提示为“运算符== 无法用于 object 和bool类型的操作数” see here:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace WindowsApplication5{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private static int flag=0;//标志变量 public Form1() { // // 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.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(80, 152); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(168, 24); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(88, 216); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(160, 24); this.button2.TabIndex = 1; this.button2.Text = "button2"; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(464, 266); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.Activated += new System.EventHandler(this.Form1_Activated); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { if(flag==1) { this.button1.Click+=new EventHandler(button2_Click); flag=0; } else { this.button1.Click-=new EventHandler(this.button2_Click); flag=1; } } private void button2_Click(object sender, System.EventArgs e) { MessageBox.Show("ok"); } private void Form1_Activated(object sender, System.EventArgs e) { } private void Form1_Load(object sender, System.EventArgs e) { this.button1.Click+=new EventHandler(button2_Click); } }} To:if(button1.Tag==true){..........//执行这些事件button1.Tag=false;}else{button1.Tag=true;}这种做法不行呀.错误提示为“运算符== 无法用于 object 和bool类型的操作数”改为:if(button1.Tag==null) button1.Tag=true;if((bool)button1.Tag){ MessageBox.Show("aaa"); button1.Tag=false;}else{ button1.Tag=true; } 我这样试了,虽说没有错误了,但是还是没有能够实现我想要的效果,真不知Tag到底该怎么来设置(在属性栏中Tag右边的框中应该填写什么呀??) 我的苯方法: 建一个整数类型(其他也可以),只要你鼠标button1_Click一次,它的值就自动加1,这样你就可以通过判断奇数或者偶数来处理了.虽然苯了点,不过还行 你可以把我button2_Click方法换成你想要执行的事件,或自己添加事件代表和事件声明 Oracle 动态sql 参数问题 一个关于HttpWebRequest的问题? 如何用正则表达检查英文单词 【分离器#1孔板压差(“H2O)】这里面的到底是占22字符位置还是23个字符位置 A,B两个窗体,如何让A窗体一直在B窗体之上 中文问题 用过亚信cmpp2.0的进来看看,急需搞手指点 C# 怎么获得鼠标第二次点击时的坐标 怎样解析PUD串?十万火急!!! 100分求c#事务处理的数据访问层的封装类 虽说只由5 条裤衩 。。。。 ;散分,鼓舞士气。。。 Access 裡的查詢![winfrom]
在类中保存一个静态的bool型变量
{
..........//执行这些事件
button1.Tag=false;
}
else
{
button1.Tag=true;
}
{
..........//执行这些事件
button1.Tag=false;
}
else
{
button1.Tag=true;
}
这种做法不行呀.错误提示为“运算符== 无法用于 object 和bool类型的操作数”
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication5
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private static int flag=0;//标志变量 public Form1()
{
//
// 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.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(80, 152);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(168, 24);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(88, 216);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(160, 24);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(464, 266);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.Activated += new System.EventHandler(this.Form1_Activated);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
if(flag==1)
{
this.button1.Click+=new EventHandler(button2_Click);
flag=0; }
else
{
this.button1.Click-=new EventHandler(this.button2_Click);
flag=1;
}
} private void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show("ok");
} private void Form1_Activated(object sender, System.EventArgs e)
{
} private void Form1_Load(object sender, System.EventArgs e)
{
this.button1.Click+=new EventHandler(button2_Click);
}
}
}
if(button1.Tag==true)
{
..........//执行这些事件
button1.Tag=false;
}
else
{
button1.Tag=true;
}
这种做法不行呀.错误提示为“运算符== 无法用于 object 和bool类型的操作数”
改为:
if(button1.Tag==null) button1.Tag=true;
if((bool)button1.Tag)
{
MessageBox.Show("aaa");
button1.Tag=false;
}
else
{
button1.Tag=true;
}
建一个整数类型(其他也可以),只要你鼠标button1_Click一次,它的值就自动加1,这样你就可以通过判断奇数或者偶数来处理了.虽然苯了点,不过还行