2014-01-19 127 views
2

我正在開發一個C#桌面應用程序。我希望我的所有打開的窗口彈出(東西與Alt鍵 + 標籤情況),每5分鐘。我在這裏看了幾個問題。他們建議使用定時器來做,但如何彈出最小化的窗口?每隔X分鐘最大化窗口

回答

2

下面是一個非常基本的例子,供您參考。

  1. 首先創建計時器。

  2. 創建時,計時器滴答將運行的功能。

  3. 然後添加到運行每次蜱時間的事件。並鏈接你的函數

  4. 內部的功能檢查,如果它已經5分鐘。如果是這樣,最大限度地 窗口

    public partial class TimerForm : Form 
    { 
        Timer timer = new Timer(); 
        Label label = new Label(); 
    
        public TimerForm() 
        { 
         InitializeComponent(); 
    
         timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called 
         timer.Interval = (1000) * (1);    // Timer will tick evert second 
         timer.Enabled = true;      // Enable the timer 
         timer.Start();        // Start the timer 
        } 
    
        void timer_Tick(object sender, EventArgs e) 
        { 
          // HERE you check if five minutes have passed or whatever you like! 
    
          // Then you do this on your window. 
          this.WindowState = FormWindowState.Maximized; 
        } 
    } 
    
0

下面是完整的解決方案

public partial class Form1 : Form 
{ 
    int formCount = 0; 
    int X = 10; 
    System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); 

    public Form1() 
    { 
     InitializeComponent(); 

     timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called 
     timer.Interval = (1000) * X;    // Timer will tick evert second 
     timer.Enabled = true;      // Enable the timer 
     timer.Start(); 
    } 

    void timer_Tick(object sender, EventArgs e) 
    { 
     FormCollection fc = new FormCollection(); 
     fc = Application.OpenForms; 

     foreach (Form Z in fc) 
     { 
      X = X + 5; 
      formCount++; 
      if (formCount == fc.Count) 
       X = 5; 

      Z.TopMost = true; 
      Z.WindowState = FormWindowState.Normal; 
      System.Threading.Thread.Sleep(5000); 
     } 
    } 
}