C# 每X分钟最大化一次窗口
我正在开发一个C#桌面应用程序。我希望我所有打开的窗口每隔5分钟弹出一次(Alt+Tab会出现这种情况)。我在这里看了几个问题。他们建议使用定时器,但如何弹出最小化窗口呢?这里有一个非常基本的示例供您使用C# 每X分钟最大化一次窗口,c#,wpf,windows,timer,C#,Wpf,Windows,Timer,我正在开发一个C#桌面应用程序。我希望我所有打开的窗口每隔5分钟弹出一次(Alt+Tab会出现这种情况)。我在这里看了几个问题。他们建议使用定时器,但如何弹出最小化窗口呢?这里有一个非常基本的示例供您使用 首先创建计时器 创建一个将在计时器计时时运行的函数 然后添加一个事件以在每次滴答声时运行。并将其链接到您的功能 在该功能内,检查是否已运行了5分钟。如果是,最大化 窗户 public partial class TimerForm : Form { Timer timer = new
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;
}
}
这是完整的解决方案
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);
}
}
}