如果程序首次运行不打开第二个表单,则打开第二个表单 [英] Open the second form if is the program first run is not Open the second form

查看:72
本文介绍了如果程序首次运行不打开第二个表单,则打开第二个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C的新手#

我有两个表格名称 form1 form2

我的主窗体是Form1 所以如果这个程序运行我想要这样做第一次隐藏Form1和Show Form2 但是两个窗体一直显示



时间默认值为1它在Formclose事件中递增1

我使用此代码检查并且show Form2

有什么不对

提前谢谢





I am new to C#
I have a two forms name form1 and form2
My main form is Form1 so i want to do this if this program runs first time hide the Form1 and Show Form2 but two forms are keep showing

time default value is 1 it's increment by 1 in Formclose event
I use this code to check and show Form2
What is the wrong
Thank in advance


private void Form1_Load(object sender, EventArgs e)
        {

           if (my_app.Properties.Settings.Default.time == 1)
           {
               this.Hide();
               Form2 sf = new Form2();
               sf.Show();
           }
        }

推荐答案

您没有显示增加.time设置的位置,但是如果你不要。保存()它,然后它将无法用于下次启动应用程序。你也没有提到你减少它的地方所以也许.time总是> 1.



这不是最好的方法,你应该检查正在运行的进程,如果你已经运行了一个,那么就显示一个不同的表单。搜索谷歌单实例应用程序C#,相同的概念除了你没有放弃,你显示不同的形式。
You don't show where you increment the .time setting, but if you don't .Save() it, then it won't be available for the next startup of the application. You also don't mention where you decrement it so maybe .time is always > 1.

This isn't the best way to do this, you should examine the running processes and if you already have one running, then show a different form. Search google for Single Instance Applications C#, same concept except you are not quitting, you are showing a different form.


这篇关于如果程序首次运行不打开第二个表单,则打开第二个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆