我如何第一次运行表单 [英] How do I run a form for the first time

查看:88
本文介绍了我如何第一次运行表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是VB.net的新手,并使用visual studio 2017在vb.net中创建项目。我正在开发一个使用sql server 2017作为后端的教堂管理系统。启动表单是登录。我还有一个用于设置sql server的表单。所以我希望sql server表单运行一次,直到创建sqlserver.dat。我使用sqlserver.dat作为我的connectionstring。所以我只需要一次运行sql server设置表单的帮助,这样当创建sqlserver.dat时它不会再次运行但会在我构建项目的任何时候运行登录表单



我尝试了什么:



正如我在vb.net中的新问题中所说的并且不知道如何去做,这就是为什么要问

Am new to VB.net and creating a project in vb.net using visual studio 2017. Am developing a church management system which uses sql server 2017 as the back end. The startup form is the login. I also have a form for setting the sql server. So i want the sql server form to run for one time until sqlserver.dat is created. Am using the sqlserver.dat as my connectionstring. So i want help on running sql server setting form for only one time so that when the sqlserver.dat is created it won't run again but will run the login form anytime i build my project

What I have tried:

As i said in the question am new in vb.net and have no idea how to go about it and thats why am asking

推荐答案

有很多解决方案,如何坚持布尔标志不再显示...

我更喜欢将它写入HKEY_CURRENT_USER注册表。

情况是,您询问注册表是否已经显示设置表单:



There are a lot of solutions, how to persist the boolean flag "Don't show again" ...
I prefer to write it to HKEY_CURRENT_USER Registry.
The scenario is, you ask Registry whether the settings form has been already shown like this:

//opening the subkey  
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\OurSettings");
bool bShowForm = true;  
              
//if it does exist, retrieve the stored values  
if (key != null)  
{  
    if (key.GetValue("ShowSettingsForm") == "0")
      bShowForm  = false;

    key.Close();  
}  

// now show form and set key to "0"
if (bShowForm  ) 
{
  // ....
  key.SetValue("ShowSettingsForm", "0");  
}


您需要查看持久值 - 这听起来很复杂,但这只是另一种说法保持运行之间的值保持不变应用程序,就像书签告诉你每次拿起书时读书的距离一样。



这不难做到,但它并不像创建变量那么简单,因为它们被设计为非持久性 - 每次加载应用程序时它们都是相同的。从这里开始:使用应用程序设置和用户设置Microsoft Docs [ ^ ]它解释了你需要做什么。您可以创建一个布尔值,其中显示已设置数据库并将其默认为false,因此每次启动应用程序时都会运行一次,如果它为假,则设置数据库。然后将其设置为true,随后将忽略它。
You need to look at persistent values - which sounds complicated, but is just another way to say "keeping a value unchanged between runs of the application", in the same way that a bookmark tells you how far through a book you had read every time you pick it up.

That's not difficult to do, but it's not as simple as just "creating a variable" because those are designed to be non-persistent - they are the same every time the app is loaded. Start here: Using Application Settings and User Settings | Microsoft Docs[^] and it explains what youj need to do. You can create a Boolean value which says "DB has been set up" and default it to false so it runs once, by reading it each time your app starts, and if it is false, you set up your DB. You then set it to true and you will ignore it all subsequent times.


这篇关于我如何第一次运行表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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