在启动时也隐藏主窗体时隐藏form2 [英] Hide form2 when main form is hide also in startup
本文介绍了在启动时也隐藏主窗体时隐藏form2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于在计算机上管理时间使用的小项目。
Form1:
I have a small project about manage time use on computer.
Form1:
public partial class Form1 : Form
{
private Timer t = new Timer();
public static int counter = 60;
public Form1()
{
InitializeComponent();
t.Tick += new EventHandler(Timer_Tick);
t.Interval = 1000;
t.Enabled = true;
t.Start();
Form2 TheForm2 = new Form2();
TheForm2.ShowDialog();
}
void Timer_Tick(object sender, EventArgs e)
{
counter -= 1;
if (counter==20)
{
MessageBox.Show("Time remaining "+counter.ToString());
}
}
}
和Form2:
And Form2:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int userVal = int.Parse(textBox2.Text);
Form1.counter += userVal;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = Form1.counter.ToString();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
Final程序:
Final program:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 TheForm = new Form1();
Application.Run();
}
}
我的尝试:
我尝试让这个应用程序在Windows启动时运行,而Form1是隐藏的。但我想让form2也隐形。它只是在用户执行应用程序时显示。我该如何解决?我只是将这个exe文件放到文件夹中启动它以使它在启动时运行。(我将尝试使用Registry)
What I have tried:
I try to make this application run on Windows start up and the Form1 is hide. But I wanna make form2 invisible also. And it just show when user excute the application. How can I solve it? I just put this exe to folder start up to make it run on start.(I'll try to make it with Registry)
推荐答案
我想你真正想要的是什么要做的是创建一个Windows服务来保持时间,很可能是在用户登录/注销时。然后,您可以编写一个单独的应用程序,用于可视化使用信息。
I think what you really want to do is create a Windows service to do the time keeping, most likely when a user logs in/out. Then you can write a separate app that can be used to visualize the usage info.
这篇关于在启动时也隐藏主窗体时隐藏form2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文