Note that there are some explanatory texts on larger screens.

plurals
  1. POC#: form switching, what based on timers events
    primarykey
    data
    text
    <p>I have some problems with switching forms in my applications. It have 2 forms: </p> <ul> <li>first: has one button for swith to second form;</li> <li>second: has timer for automatical switching to first form and button for manual switch to first form.</li> </ul> <p>If I click button, Application executes method <strong>logOut</strong> and it works. If it executes with events of timer - it doesn't work. I need help to understand why it doesn't work in this way?</p> <p>Code for first form</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private Form2 frmm2; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { frmm2 = new Form2(this); frmm2.Show(this); this.Hide(); } } } </code></pre> <p>Second form</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Timers; namespace WindowsFormsApplication1 { public partial class Form2 : Form { private System.Timers.Timer tmr; private Form2 frm2; private Form1 frm1; public Form2(Form1 f1) { InitializeComponent(); tmr = new System.Timers.Timer(); tmr.Elapsed += new ElapsedEventHandler(OnTimedEvent); tmr.Interval = 10000; tmr.Enabled = true; frm1 = f1; frm2 = this; } public void OnTimedEvent(object source, ElapsedEventArgs e) { tmr.Stop(); MessageBox.Show("Before timer event"); logOut(); MessageBox.Show("After timer event"); } private void button1_Click(object sender, EventArgs e) { logOut(); } public void logOut() { if (tmr != null) { tmr.Stop(); tmr = null; } /* * It doesn't work directly. I'll try to do it in another way. this.Hide(); this.Owner.Show(); this.Owner.Activate(); */ frm1.Show(); frm1.Activate(); frm2.Close(); } } } </code></pre> <p>Thanks for answers!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload