如何关闭当前表单并显示另一个表单? [英] How to close current form and show another one?

查看:122
本文介绍了如何关闭当前表单并显示另一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个C#windows应用程序。

我想在第一个表单的加载事件中显示第二个表单,并在表单第二个表单打开后隐藏第一个表单。



我的尝试:



I had created a C# windows application.
I want to show second form at the load event of first form and hide that first form after form second is open.

What I have tried:

login l = new login();

using (SqlConnection cn = new SqlConnection(conn))
{
    int remains = getdifff();
    cn.Open();
    SqlCommand cmd = new SqlCommand("select ipaddress from KeyDetails where ipaddress='" + label1.Text + "' ", cn);
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
        if (remains <= 365 && remains >= 1)
        {
            l.Show();
            this.Hide();
        }
        else
        {
            label4.Show();
        }
    }
    else
    {
        this.Show();
    }
    this.Hide();
}

推荐答案

可能是你在主表单加载它时试图显示启动画面数据。

看看这些:

简单易用的C#SplashScreen,编码最少 [ ^ ]

[ ^ ]
Probably, you're trying to display a splash screen while your main form loads it's data.
Have a look at these:
Simple Easy C# SplashScreen with Minimal Coding[^]
Yet Another Splash Screen in C#[^]


如果login是第二种形式,则只需执行以下操作:



If "login" is the second form, you need only to do:

this.Hide();
login l = new login();
l.Show();





您可以在按钮单击事件上绑定此代码段以进行测试。



You can bind this snippet of code on a button-click event to test it.


这篇关于如何关闭当前表单并显示另一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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