Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Form1 will show and close automatically within for 10 sec interval,
Form2 will show and close automatically within for 10 sec interval,
'
'
Form10 will show and close automatically within for 10 sec interval
repeatedly
Every form will show and close 10sec interval
without using any control.
Please help me out....

What I have tried:

public RadForm1()
{
InitializeComponent();
MyTimer.Interval = 3000;
MyTimer.Tick += new EventHandler(MyTimer_Tick);
MyTimer.Start();
}
Form frmShow = new Form();


private void MyTimer_Tick(object sender, EventArgs e)
{
this.Hide();
SqlConnection con = new SqlConnection(connection);
con.Open();
SqlCommand cmd = new SqlCommand("Select Frm_Name from Form_Master where Status='Y' order by Frm_Name", con);
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{

string Frm_Name = (string)rdr["Frm_Name"];
Assembly frmAssembly = Assembly.LoadFrom(Application.ExecutablePath);
foreach (Type type in frmAssembly.GetTypes())
{
if (type.Name == Frm_Name)
{
frmShow = (Form)frmAssembly.CreateInstance(type.ToString());
frmShow.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
this.StartPosition = FormStartPosition.CenterScreen;
MyTimer.Enabled = false;
Timer_Tick();
frmShow.Close();

}

}
}
} con.Close();
}


public void Timer_Tick()
{
frmShow.Show();
System.Threading.Thread.Sleep(2000);

}
Posted
Updated 20-Feb-18 21:13pm

1 solution

this below code is for predefined forms where i have created instance for a2 form and a3 form as g and j ..

public partial class a1 : Window
   {
       public static int count = 0;
       Timer timer;
       public int Interval;
       List<string> li;
       public a1()
       {
           InitializeComponent();
           int interval = 10 * 1000;
           timer = new Timer(interval);
           Interval = interval;

           timer.Elapsed += new ElapsedEventHandler(a);timer.Start();
           timer.AutoReset = true;
       }
       private void a(object sender,ElapsedEventArgs elapsedEvent)
       {
           StopTimer();
           bool AutoRepeat = true;
         //timer.Interval = 100; //any value
         //  timer.Start();
           if (AutoRepeat)
               StartTimer(); count++;
           this.Dispatcher.Invoke(() =>
           {
               this.Hide();
                  });
           if (count == 1)
           {
               this.Dispatcher.Invoke(() =>
               {
                   g.Show();
               });

           }
           else if (count == 2)
           {
               this.Dispatcher.Invoke(() =>
               {
                   g.Close();
               });
               this.Dispatcher.Invoke(() =>
               {
                   j.Show();
               });

           }
           else
           {
               this.Show();
           }
       }

       a2 g = new a2();a3 j = new a3();
       public void StopTimer()
       {
           timer.Stop();
           timer.Enabled = false;
       }
       public void StartTimer()
       {
           StopTimer();
           timer.Enabled = true;
           timer.Interval = Interval;
           timer.Start();
       }
   }
 
Share this answer
 
Comments
sharat naik 21-Mar-18 22:44pm    
Its working nice.................

Timer Active_Timer = new Timer();
Form frmShow = new Form();

public MainForm()
{
InitializeComponent();
Active_Timer.Interval = 100;
Active_Timer.Tick += new EventHandler(Active_Timer_Tick);
Active_Timer.Start();
}

private async void Active_Timer_Tick(object sender, EventArgs e)
{
bool IsOpen = false;
this.Hide();
SqlConnection con = new SqlConnection(connection);
con.Open();
SqlCommand cmd = new SqlCommand("select Form_Name from Display_External_Selected where Type=4", con);
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
rdr.Read();
var Frm_Name = (string)rdr["Form_Name"];
var str_array = Frm_Name.Split(',');
SqlCommand cmdd; SqlDataReader reader; SqlConnection conn;

for (var i = 0; i < str_array.Length; i++)
{
Active_Timer.Stop();
conn = new SqlConnection(connection);
conn.Open();
cmdd = new SqlCommand("select Form_Active from Display_Parameters where Form_No=" + str_array[i] + "", conn);
reader = cmdd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
var Active_Frm_Name = (string)reader["Form_Active"];
IsOpen = true;
string formTypeFullName = string.Format("{0}.{1}", this.GetType().Namespace, Active_Frm_Name);
Type type = Type.GetType(formTypeFullName, true);
Form frmShow = (Form)Activator.CreateInstance(type);
frmShow.Location = new Point(0, 0);
frmShow.Size = Screen.PrimaryScreen.WorkingArea.Size;
frmShow.StartPosition = FormStartPosition.CenterScreen;
if (IsOpen == true)
{
frmShow.Show();
IsOpen = false;
}
if (IsOpen == false)
{
await Task.Delay(3000);
frmShow.Close();
}
Active_Timer.Enabled = false;
Active_Timer.Start();
Active_Timer.Interval = 1000;

}

}
con.Close();
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900