开发者

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 ad开发者_运维问答ding 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜