Hi!
I have a requirement where I need to display multiple forms one after
the other like a slide show. These are in the same application.
Basicall on selection of a menu item it should start then clicking on
any of th screens or tray icon it should stop.
I tried the following (To start it on pressing escape on form1 and end
it when escape is again
pressed on form1):
this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.Form1_Ke yDown);
In the handler I wrote the following code :
private void Form1_KeyDown(object
sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Escape)
{
if(null == thread)
{
currentSize = this.Size;
ThreadStart delegateThread = new
ThreadStart(this.KioskDisplay);
thread = new Thread(delegateThread);
running = true;
thread.Start();
}
else
{
running = false;
//thread.Abort();
thread.Join();
thread = null;
this.Show();
}
}
}
The code for the slide show function :
private void KioskDisplay()
{
ArrayList forms = new ArrayList();
forms.Add(this);
forms.Add(form2);
forms.Add(form3);
forms.Add(form4);
this.Hide();
form2.Hide();
form3.Hide();
form4.Hide();
Form currentForm = null;
for(int i = 0;true == running; i++)
{
if(null != currentForm)
currentForm.Hide();
currentForm = (Form)forms[i%4];
currentForm.Show();
currentForm.Refresh();
currentForm.Focus();
System.Threading.Thread.Sleep(2000);
}
}
My Question : 1. Is there a better way of doing it.
2. In my case once I do escape it starts, on
second escape it stops, but
pressing the escape again shows only form1
and other forms don't appear
in the loop only form1 comes and hides others
are not shown.
Any pointers to it will be highly appreciated.
regards,
Rajat Jain