locked
How to clear button click event during button is disabled? RRS feed

  • 問題

  • Hi,

    I've a button click problem.
    After I click the button, the process is

    1. set enable property to false
    2. create a thread to do something, and the main thread wait it until it  finished   (about 5~6 sec)
    3. set enable property to true again

    During the process, if I click the button again,
    the button can't be clicked immediately, but the button click event is postponed after the button is re-enabled

    Is it a bug of .net API, or there is something wrong of my procedure?
    Thanks for any response
    2010年3月5日 上午 09:13

解答

所有回覆

  • Hi,

    In fact that the 'click' event wouldn't be triggered if the value of enable property was set to false.

    I have tested the issue in my environment and didn't find the problem.
    You can create a simple solution and test it again.

     private void button1_Click(object sender, EventArgs e)
            {
                this.button1.Enabled = false;
                Thread.Sleep(2000);
                MessageBox.Show("test click event");                             this.button1.Enabled = true;
    
            }

    Microsoft Online Community Support
    2010年3月8日 上午 03:15
  • Hi, KeFang

    Thanks for your reply.
    I tried your sample code, but the problem still exists.

    I upload my code here.
    http://www.badongo.com/file/21074493


    enviroment: c# express (debug run), .net 3.5
    os: win xp

    maybe there is something wrong for my project setting or button setting?
    2010年3月8日 上午 03:55
  • Hi,

    I am sorry that I can't download the project you mentioned.

    I create a simple test project for you. You can download it and test it again.
    http://files.cnblogs.com/wuwei_chen/ButtonEnableDemo.rar

    My environment:Windows7+Visual Studio 2008

    Or you can test it with the other computer 
    Microsoft Online Community Support
    2010年3月8日 上午 06:09
  • Hi, KeFang

    Thanks~
    I have tried your code. It works well.
    But if I change the MessageBox.show() to Console.Write()
    The problem still exists


    Can you try this case on your computer?
    Thanks for your help~~
    2010年3月8日 上午 08:28
  • Hi,

    In Winform application,don't use the Console.Write()  which belongs to Console application .
    Microsoft Online Community Support
    2010年3月9日 上午 02:07
  • Hi, KeFang

    I modify code to:

    this.button1.Enabled = false;
    Thread.Sleep(2000);
    this.button1.Enabled = true;


    The problem still exists.


    If I click button again during the 2000ms, the button click event is postponed after the button is enabled
    It is not the console problem.
    2010年3月9日 上午 05:50
  • Hi,

    Can you send your project to my email v-kefc@microsoft.com?
    So I can check it in detail.
    Microsoft Online Community Support
    2010年3月9日 上午 10:06
  • Hi, KeFeng

    I have sent you the sample code.
    THANKS FOR YOUR HELP
    2010年3月9日 上午 10:23
  • Hi,

    It seems that the issue does exists. If I removed the 'MessageBox.Show()', the issue would be reproduced.

    I am sorry I can't help you on this point. You can go to the following website to post the issue about the Visual Studio.
    https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=14651&wa=wsignin1.0 
    Microsoft Online Community Support
    • 已標示為解答 KeFang Chen 2010年3月11日 上午 06:29
    2010年3月10日 上午 01:45
  • Hi, KeFeng

    Thanks.
    I'll try later.
    2010年3月10日 上午 08:33