如何使.ShowDialog只在Forms中显示一次 [英] how to make .ShowDialog show only once in Forms

查看:84
本文介绍了如何使.ShowDialog只在Forms中显示一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我是编程的新手请帮助我解决我的小问题。

我的启动画面显示.ShowDialog方法

所以我的问题是每一个时间我访问我的第一个表格(登录)Splash Screen总是显示。

如何让我的Splashscreen只显示一次



<大>这是我的代码(登录表格)

  public 登录()
{
InitializeComponent();

new SplashWindow()。ShowDialog();
// 这是Splash显示的地方

}





i知道这是错的,但我试试这个

  public  Login()
{
InitializeComponent();
bool first = false ;
if (first == true
{

}
else
{
new SplashWindow()。的ShowDialog();
first = true ;
}
}







这就是我改变的方式表格

 Proj.MainWindow ma =  new  Proj.MainWindow(); 
App.Current.MainWindow = ma;
this .Hide();
ma.Show();
this .Close();

解决方案

使用调试器;你会看到发生了什么。根据您的描述,您的方法 Login 看起来不止一次。这里的问题是:您不会在代码中显示每个实例和每个类的内容。比如说,如果第一个是静态的,则不会显示。当然,在同一个实例上多次调用 InitializeComponent 调用该方法是明显的错误,并且在同一个类上调用它是错误的代码设计风格,大多数情况。



顺便问一下,请参阅我的相关主题文章:希望你在这里......只有一次 [ ^ ]。



-SA

Hi Everyone I'm newbie to programming please help me with my little problem.
I make my splash screen show on .ShowDialog method
so my problem is every time I access my first form(login) Splash Screen always shows.
How to make my Splashscreen Show only once

this is my code (login-form)

public Login()
        {
            InitializeComponent();

            new SplashWindow().ShowDialog();
            //this is where Splash shows

        }



i know this is wrong but i try this

public Login()
       {
           InitializeComponent();
           bool first = false;
           if (first == true)
           {

           }
           else
           {
             new SplashWindow().ShowDialog();
             first = true;
           }
       }




this is how i change forms

Proj.MainWindow ma = new Proj.MainWindow();
                   App.Current.MainWindow = ma;
                   this.Hide();
                   ma.Show();
                   this.Close();

解决方案

Use the debugger; and you will see what's going on. From your description, it looks like your method Login is called more than once. The issue here is: you don't show in your code what do you do per instance and what per class. Say, it's not shown if first is static or not. Certainly, calling the method with the call to InitializeComponent on the same instance more than once is the apparent bug, and calling it on the same class is the bad code design style, in most cases.

By the way, please see my article on related topic: Wish You Were Here… Only Once[^].

—SA


这篇关于如何使.ShowDialog只在Forms中显示一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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