如果满足某些条件,如何绕过主要表单Visual Studio 2008 [英] how to bypass the main form if some condition is satisfied visual studio 2008

查看:63
本文介绍了如果满足某些条件,如何绕过主要表单Visual Studio 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我被困在一个部分中,以绕过run.ie程序加载时加载的主要表单.如果满足某些条件,则应关闭主窗体,并运行其他选定的窗体
我的代码是:



i am stuck in a part to bypass the main form that loads when the program on run.ie. if some codition is satisfied then the main form should be closed and other selected form should run
my code is :

private void frmEntrySecretKey_Load(object sender, EventArgs e)
      {

  string sk = BllLoginHelper.checkSecretKeys();
            if (sk == null)
            {
                frmLogin frmlogin = new frmLogin();
                frmlogin.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("there is A KEY");
            }

      }



但这没用
但是我试图在按钮单击事件之后放一个
相同的代码有效



but it did not worked
but i tried to put after a button click event
the same code worked
can any one help me with this..

推荐答案

在第一次显示表单之前发生好加载事件.

由于可能还有其他有用的Form事件,因此请在调用frmEntrySecretKey.Show()方法之前尝试检查此情况.如果这是您的第一表格",请检查Program.cs并以适当的方式对其进行修改.如果您不清楚某些地方,请改善此问题.

一些参考:

表单事件 http://msdn.microsoft.com/en-us/library/td1s43eb.aspx [^ ]

更新:

根据您的评论,这是您应该尝试的方法.

在您的项目中打开一个名为Program.cs的文件.
在里面应该找到类似的东西

Well Load event occurs before a form is displayed for the first time.

As there are other Form events that may be useful, try to check this condition before the frmEntrySecretKey.Show() method is called. If this is your "first form" check the Program.cs and modify it in a proper way. If there is something that you are not clear, improve this question.

Some references:

Form events http://msdn.microsoft.com/en-us/library/td1s43eb.aspx[^]

UPDATE:

Based on your comment, this is what you should try.

Open a file in your project called Program.cs

Inside you should find something like

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new frmEntrySecretKey());
    }
}



并尝试在
中进行更改



And try to change it in

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        string sk = BllLoginHelper.checkSecretKeys();
        if (sk == null)
        {
            Application.Run(new frmLogin());
        }
        else
        {
            Application.Run(new frmEntrySecretKey());
        }
    }
}



这不是一个优雅的解决方案,但可以完成您的工作.这样,您就可以继续进行操作,然后在将来寻找更优雅的解决方案.

欢呼!



It is not an elegant solution but it will do your job. In this way you will be able to proceed and then in the future search for a more elegant solution.

Cheers!


使用预处理程序#if指令可能会帮助您-请参阅 ^ ]有关此指令的更多文档.
Using a preprocessor #if directive might help you out - see here[^] for more documentation on this directive.


这篇关于如果满足某些条件,如何绕过主要表单Visual Studio 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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