user2553430
user2553430

Reputation: 29

How to rotate windows forms in every 20 secs using timer in windows application?

I have four windows forms namely,
form1.vb,
form2.vb,
form3.vb,
form4.vb.

And also i have one master page namely form5.vb. So i have rotate one by one above four windows forms in form5.vb with every 20 secs . how to do it ?

Upvotes: 0

Views: 843

Answers (3)

CC Inc
CC Inc

Reputation: 5928

Basically, you create a timer and call the function BringToFront on each form.

In C#:

static int counter = 1;

static void StartRotating()
{
    System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
    myTimer.Interval = 20000; // 20 seconds 
    myTimer.Tick += new EventHandler(TimerEventProcessor);
    myTimer.Start();
}

private static void TimerEventProcessor(Object myObject,
                                        EventArgs myEventArgs) {
    // you could use a switch statement also
    if(counter==1) form1.BringToFront();
    if(counter==2) form2.BringToFront();
    if(counter==3) form3.BringToFront();
    if(counter==4) { 
        form4.BringToFront(); 
        counter=0; //reset counter
        }
    counter++;
}

Upvotes: 1

Ehsan
Ehsan

Reputation: 32701

You need to keep an index to know which form is currently displayed and then in the timer elapsed event you can do this

            formtoshow.TopMost = true;
            formtoshow.BringToFront();

Upvotes: 0

Keith Nicholas
Keith Nicholas

Reputation: 44306

On a 20 second timer you can call 'BringToFront' on each form.

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.bringtofront.aspx

Upvotes: 1

Related Questions