类中保存一个布尔字段。bool runEvent;
在按钮的点击处理函数中。。
runEvent ^= true;

解决方案 »

  1.   

    同意楼上的方法
    在类中保存一个静态的bool型变量
      

  2.   

    按钮控件有Tag属性,就是干这个用的,你点击的时候纪录一下就行了
      

  3.   

    if(button1.Tag==true)
    {
    ..........//执行这些事件
    button1.Tag=false;
    }
    else
    {
    button1.Tag=true;
    }
      

  4.   

    在类中保存一个静态的bool型变量???如何声明一静态变量?
      

  5.   

    if(button1.Tag==true)
    {
    ..........//执行这些事件
    button1.Tag=false;
    }
    else
    {
    button1.Tag=true;
    }
    这种做法不行呀.错误提示为“运算符== 无法用于 object 和bool类型的操作数”
      

  6.   

    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);
    }
    }
    }
      

  7.   

    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;
    }
      

  8.   

    我这样试了,虽说没有错误了,但是还是没有能够实现我想要的效果,真不知Tag到底该怎么来设置(在属性栏中Tag右边的框中应该填写什么呀??)
      

  9.   

    我的苯方法:
        建一个整数类型(其他也可以),只要你鼠标button1_Click一次,它的值就自动加1,这样你就可以通过判断奇数或者偶数来处理了.虽然苯了点,不过还行
      

  10.   

    你可以把我button2_Click方法换成你想要执行的事件,或自己添加事件代表和事件声明