如何在 C# 中最小化单个 Windows 应用程序表单 [英] How to minimize a single Windows application form in C#

查看:23
本文介绍了如何在 C# 中最小化单个 Windows 应用程序表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表格,Form1 和 Form2.我目前在启动表单(Form1)中有一个按钮可以加载 Form2.我想要做的是使 Form1 最小化,并且仅在被告知加载后才显示 Form2,以便在显示 Form2 时 Form1 不在后台.

I have two forms, Form1 and Form2. I currently have a button in the startup form(Form1) that loads up Form2. What I would like to do is have Form1 become minimized and only show Form2 once it is told to load so that Form1 is not in the background while Form 2 is shown.

到目前为止,我已经尝试过诸如:

So far I have tried things such as:

this.WindowState = FormWindowState.Minimized;

但我遇到的问题是它也会导致 Form2 最小化.有没有办法专门导致仅 Form1 受到影响或解决此问题?

but the problem I'm having is that it causes Form2 to become minimized as well. Is there a way to specifically cause only Form1 to be affected or work around this problem?

你会在下面找到我的代码,我可能犯了一些错误!

below you will find my code, I may have made some mistakes!

  Form2 add = new Form2();
        this.WindowState = FormWindowState.Minimized;
        add.ShowDialog();

我也尝试将 windowstate 放在 showdialog 后面,但它可能不起作用,因为它只会在对话框完成工作后执行.

I had also tried putting the windowstate behind the showdialog but it may not work because it will only execute after the dialog is done working.

推荐答案

您的问题有两个原因.

  1. 您正在使用 ShowDialog 将 Form2 作为模态对话框启动.提示:阅读有关模态对话框的信息
  2. 您需要在显示 Form2 之后最小化
  1. You're using ShowDialog which launches Form2 as a modal dialog. Hint: Go read about modal dialogs
  2. You need to minimize after showing Form2

将您的代码更改为:

var add = new Form2();
add.Show();
WindowState = FormWindowState.Minimized;

这篇关于如何在 C# 中最小化单个 Windows 应用程序表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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