2014-01-19 108 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); 
     } 
    } 
}