首次启动应用程序时显示对话框 [英] Show dialog on first start of application

查看:182
本文介绍了首次启动应用程序时显示对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在第一次(仅第一次)启动程序时,是否有简单的方法来显示对话框?对于某种指令或指定设置?

解决方案

您可以将其保存为设置中的布尔,您应该检查第一个表单的加载事件。
您的设置文件应该有一个设置,我称之为FirstRun,执行以下步骤:


  1. 右键单击您的项目

  2. 点击属性

  3. 点击设置标签页(可能在左边)

  4. 添加设置我做过如上图所示

注意: Scope 可以更改应用程序,如果这是您的应用程序的需要,因为您没有在您的问题中提及。



您的设置文件应如下图所示:





public void Form1_Load(object sender,EventArgs e)
{
if((bool)Properties.Settings.Default [FirstRun] == true)
{
//第一个应用程序运行
//更新设置
Properties.Settings.Default [FirstRun] = false;
//保存设置
Properties.Settings.Default.Save();
//创建要显示的对话框的新实例
FirstDialogForm fdf = new FirstDialogForm();
//显示对话框
fdf.ShowDialog();
}
else
{
//不是运行应用程序的第一次。
}
}

注意:从我的手机写下来,所以我无法编译测试

编辑:从桌面检查代码并添加图像。


Is there an easy way to show an dialog when the program is started for the first time (and only the first time), for some kind of instruction or specifying settings?

解决方案

You could save it as a bool in your settings and you should check at load event of first form. Your settings file should have a setting that I called "FirstRun" do this with following steps:

  1. Right click your Project
  2. Click "Properties"
  3. Click "Settings" tabpage(probably on the left)
  4. Add setting like I did as seen in image above

Note: The Scope can be changed to "Application", if that is your application's need, since you didn't mention in your question.

Your Settings file should look like image below:

public void Form1_Load(object sender, EventArgs e)
{
    if((bool)Properties.Settings.Default["FirstRun"] == true) 
    {
       //First application run
       //Update setting
       Properties.Settings.Default["FirstRun"] = false;
       //Save setting
       Properties.Settings.Default.Save();
       //Create new instance of Dialog you want to show
       FirstDialogForm fdf = new FirstDialogForm();
       //Show the dialog
       fdf.ShowDialog();
    }
    else
    {
       //Not first time of running application.
    }
}

Note: wrote this from my phone, so I couldn't compile to test
Edit: Checked code and added image from desktop.

这篇关于首次启动应用程序时显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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