C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.78041 の関連記事表示

<< 0 >>
■78041  Re[9]: 数分間操作がなかった場合のイベントについて
□投稿者/ 魔界の仮面弁士 -(2015/12/09(Wed) 11:50:42)
    No78039 (straf さん) に返信
    > わざわざ書いていただきありがとうございます。
    > 少し、理解に時間がかかりそうなので、一度解決済みで終わらせます。

    this.components の null チェックが抜けていたので、修正して再掲。

    Timer を自前で new するのではなく、デザイナで貼っている場合は
    気にしなくて良いことですが、一応念のため。



    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    namespace WindowsFormsApplication1
    {
     public partial class Form1 : Form
     {
      private Timer timer1;
      private Label label1;
      public Form1()
      {
       InitializeComponent();
       this.label1 = new Label() { Text = "0", AutoSize = true };
       this.Controls.Add(this.label1);
       if (this.components == null) this.components = new System.ComponentModel.Container();
       this.timer1 = new Timer(this.components) { Interval = 50 };
       this.timer1.Tick += delegate
       {
        uint[] last = {8, 0};
        GetLastInputInfo(last);
        var span = new TimeSpan((Environment.TickCount - last[1]) * 10000);
        this.label1.Text = span.ToString();
        if (span.TotalMinutes > 1.0F)
        {
         this.timer1.Stop();
         MessageBox.Show("1分経過したので終了します");
         this.Close();
        }
       };
       this.timer1.Start();
      }

      [DllImport("User32")]
      private static extern bool GetLastInputInfo(uint[] lastInputInfo);
     }
    }
記事No.78005 のレス / END /過去ログ132より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -