2017-03-24 12 views
0

タイムアウトセッションとして機能するメインアプリケーション内にタイマー機能があります。しかし、私は、タイマーの間隔とサブフォームを介してオンとオフを切り替える機能を変更したいが、設定を変更するために別のフォーム内のタイマー機能要素を使用することはできません。以下は私のコードスニペットです。任意のヒントや例をいただければ幸いです。メインフォームのサブフォームからタイマー設定を変更する方法C#

試み: メインフォーム

private void Booyaa_Load(object sender, EventArgs e) 
     { 
      BooyaaTimer.Interval = 45 * 60 * 1000); // 45 mins 
      BooyaaTimer.Tick += new EventHandler(BooyaaTimer_Tick); 
      BooyaaTimer.Start(); 
      if (!Properties.Settings.Default.SettingShutdown) 
      { 
       MessageBox.Show("Not properly shut down"); 
       GetPass pass = new GetPass(); 
       DialogResult result = pass.ShowDialog(); 
       if (result == DialogResult.OK) { 

        Properties.Settings.Default.SettingShutdown = true; 
       Properties.Settings.Default.Save(); 
      } 
      else 
      { 
       Close(); 
      } 
      } 

private void BooyaaTimer_Tick(object sender, EventArgs e) 
     { 
      MessageBox.Show("TIME IS UP"); 

      GetPass pass = new GetPass(); 
       DialogResult result = pass.ShowDialog(); 
       if (result == DialogResult.OK) 
       { 

       Show(); 
       Properties.Settings.Default.SettingShutdown = true; 
       Properties.Settings.Default.Save(); 
      } 
       else 
      { 

       BooyaaTimer.Start(); 
       Properties.Settings.Default.SettingShutdown = false; 
       Properties.Settings.Default.Save(); 
       Hide(); 
      } 

      } 

タイマーコントロール、私は推測を作るつもりです

public object BooyaaTimer { get; private set; } 



      private void btn_confirm_Click(object sender, EventArgs e) 
      { 


BooyaaTimer.Interval = Int32.Parse(textBox1.Text); // gives error on interval 

      } 
+1

'btn_confirm_Click'コードが不完全であるに作成されます。 –

+0

@ JohnnyMopp私の主張は、メインフォームからインターバル機能を使用することができないため、私はそれを続行できないということです。 –

+0

「タイマー」とは何ですか?そしてなぜ 'BooyaaTimer'が' System.Windows.Forms.Timer'オブジェクトではなく 'object'であるのでしょうか? [mcve]の作成方法をお読みください。 –

答えて

1

を形成します。タイマは、メインフォーム

public partial class Form1 : Form { 
    Timer BooyaaTimer = new Timer(); // Or this is created in Designer 

    void SomeFunctionThatCreatesTheOtherForm() { 
     TimerControlsForm form2 = new TimerControlsForm(); 
     // Pass the timer to form2 
     form2.BooyaTimer = BooyaTimer; 
     form2.ShowDialog(); 
    } 
} 

そして、他の形態

public partial class TimerControlsForm : Form { 
    // This has to be a Timer object 
    public Timer BooyaTimer {get; set;} 

    private void btn_confirm_Click(object sender, EventArgs e) { 
     BooyaaTimer.Interval = Int32.Parse(textBox1.Text); 
    } 
} 
+0

私はこのエラーを回避するために管理しています:public static System.Windows.Forms.Timer BooyaaTimer {get;内部セット;}しかし、私はまだBooyaaTimer.Interval = Int32.Parse(textBox1.Text)で例外を取得します。番号を入力してbtn_confirmを押したとき –

+0

エラーは何ですか? –

+0

処理されない例外 –

関連する問題