简体   繁体   中英

C# how to add focus to button issue

I have a windows form application which has a text box and 3 buttons. Now i need to add focus to a button for 1 second, and then add focus to the other button for a second.. like wise to adding focus to all these 3 buttons for 1 second each.

How do i do this. I have tried everything but nothing worked. Can someone help me here or link me to a website that does this.

i am using Visual Studio 2008,

The easiest way would be to throw a timer control on your form and define an integer switch that would help you determine which button to set focus to. Something along the lines of:

private int button = 0;
private void OnTimerTick(object sender, EventArgs e) {
    switch (button) {
        case 0:
             button0.Focus();
             button++;
             break;
        case 1:
             button1.Focus();
             button++;
             break;
        case 2:
             button2.Focus();
             button++;
             break;
        default:
             button = 0;
             break;
     }
}

Your timer would of course be set to 1000ms, and you could disable or stop it when you are done. Mind, the user can still change focus on their own while you do this.

Not sure why you would want to do that but maybe you can use a Timer and set it's interval to 1000ms and on it's Tick rotate focus as you want. Mind you, it's very user-unfriendly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM