如何使用c#在visual studio中的Windows窗体应用程序中更改启动窗体 [英] how to change start form in windows form application in visual studio using c#

查看:148
本文介绍了如何使用c#在visual studio中的Windows窗体应用程序中更改启动窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我正在开发一个应用程序,我已经创建了一个序列号数据库来激活产品。当您输入正确的序列号时,它会注册产品并提供对产品的访问权限,但当用户关闭应用程序并打开应用程序时,它会再次询问序列号。有没有办法,一旦用户输入正确的序列,那么当应用程序关闭并再次打开时它不会要求串行!

解决方案

您的应用程序可能有一个程序.cs文件或类似语句如:



System.Windows.Forms.Application.Run(new Form1());



您应该可以将其更改为以下内容:



  if (app  未注册)System.Windows.Forms.Application .Run( new  registrationform()); 
如果(app 已注册)System.Windows.Forms.Application.Run( new mainform());





测试应用是否为注册可能会在DAL中实施。



确保将数据访问代码放在一个单独的类中;不在表单中。


正确输入密钥后,您可以将应用程序标记为在数据库或任何其他商店(如注册表)中注册。

下次当用户打开应用程序时,检查此存储是否已注册状态,然后决定是否需要显示串行框。


签出 System.Windows.Forms.ApplicationContext [ ^ ]



我使用这个类首先显示一个登录表单,然后是主表单。



Program.cs

 静态  void  Main()
{
var loginSeq = new LoginSequence();
Application.Run(loginSeq);
}





LoginSequence.cs

  public   class  LoginSequence:ApplicationContext 
{
private LoginForm _login;

// Ctor - 首先显示LoginForm。
public LoginSequence()
{
_login = new LoginForm();
_login.Closed + = LoginFormClosed;
_login.Show();
}

/// < 摘要 >
/// LoginForm已关闭
/// < / summary >
private void LoginFormClosed( object sender,EventArgs e)
{
// 检查登录结果
如果(_ login.DialogResult == DialogResult.OK)
{
// 有效
_login.Closed - = LoginFormClosed;
_login = null ;

// Show MainForm
MainForm = new MainForm();
MainForm.Show();
}
其他
{
// < span class =code-comment>无效的用户登录
ExitThread();
}
}
}





它可以正常使用。


hey,

i am developing an application for which i have created a database of serial numbers to activate the product. When your enters the correct serial number then it registers the product and provide access to the product but when the user close the application and open the application it again asks for serial number. Is there any way that once user enters the correct serial then it will not ask for serial when the application is closed and opened again!

解决方案

Your application likely has a Program.cs file or similar with statement like:

System.Windows.Forms.Application.Run ( new Form1() ) ;

You should be able to change it to something along the lines of:

if ( app is not registered ) System.Windows.Forms.Application.Run ( new registrationform() ) ;
if ( app is registered ) System.Windows.Forms.Application.Run ( new mainform() ) ;



The test for whether or not the app is registered will likely be implemented in the DAL.

Be sure to have the data access code in a separate class; not in the form.


Once the key is entered correctly, you can mark the application as registered in a database or any other store like registry.
Next time when the user opens the application, check this storage for registered status and then decide whether the serial box needs to be displayed or not.


Check out System.Windows.Forms.ApplicationContext[^]

I use this class to first show a login form, and then the main form.

Program.cs

static void Main()
{
  var loginSeq = new LoginSequence();
  Application.Run(loginSeq);
}



LoginSequence.cs

public class LoginSequence : ApplicationContext
{
        private LoginForm _login;

        // Ctor - Show LoginForm first.
        public LoginSequence()
        {
            _login = new LoginForm();
            _login.Closed += LoginFormClosed;
            _login.Show();
        }

        /// <summary>
        /// LoginForm has closed
        /// </summary>
        private void LoginFormClosed(object sender, EventArgs e)
        {
            // Check LoginFrom result
            if (_login.DialogResult == DialogResult.OK)
            {
                // Valid
                _login.Closed -= LoginFormClosed;
                _login = null;

                // Show MainForm
                MainForm = new MainForm();
                MainForm.Show();
            }
            else
            {
                // Invalid user login
                ExitThread();
            }
        }
}



And it is work fine for my use.


这篇关于如何使用c#在visual studio中的Windows窗体应用程序中更改启动窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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