简体   繁体   English

最小化表单应用程序 c# 时任务栏图标消失

[英]Taskbar icon disappears when minimizing form application c#

When I'm changing windows(forms), my application's icon disappears from taskbar.当我更改窗口(窗体)时,我的应用程序图标从任务栏中消失。 So for opening the application, users need to click ALT+TAB to select the form which is hidden from taskbar.所以要打开应用程序,用户需要点击 ALT+TAB 到 select 从任务栏隐藏的窗体。 After users choose application, icon comes to taskbar again.用户选择应用程序后,图标再次出现在任务栏。 I don't want my applcation icon disappears from taskbar.我不希望我的应用程序图标从任务栏中消失。

My codes are below:我的代码如下:

//Program.cs
[STAThread]
static void Main()
{
    Application.Run(new LoginPage());
}

Login Page is application's first screen that gets username and password.登录页面是应用程序获取用户名和密码的第一个屏幕。 After clicking submit button application is going to main page.单击提交按钮后,应用程序将进入主页面。

//LoginPage.cs  
private void submitBtn_Click(object sender, EventArgs e)
{
    MainPage mainPage= new MainPage();                   
    mainPage.Show();
    this.Hide();
}

Lets say I have a button on main page for going to another form.假设我在主页上有一个按钮可以转到另一个表单。 Here when I click the page1 button taskbar icon disappears.这里当我点击page1按钮时任务栏图标消失了。

//MainPage.cs
private void page1Btn_Click(object sender, EventArgs e)
{
    Page1 page1 = new Page1();
    page1.Show();
    this.Hide();
}

After some research I found one solution for that but there is another problem which I cannot minimize the form correctly.经过一些研究,我找到了一个解决方案,但还有另一个问题是我无法正确最小化表单。

When I change the codes above with below当我用下面的代码更改上面的代码时

//MainPage.cs
private void page1Btn_Click(object sender, EventArgs e)
{
    Page1 page1= new Page1();
    page1.ShowInTaskbar = false;
    page1.Owner = this;
    page1.ShowDialog();
    this.Hide();     
}

Here, I also need to modify Page1 as below在这里,我还需要修改Page1如下

//Page1.cs
private void Page1_FormClosed(object sender, FormClosedEventArgs e)
{
    MainPage mainPage = new MainPage();
    mainPage.Show();
}

Here I can successfully go to page1 step by step (without disappearing the taskbar icon).到这里我可以一步一步成功go到page1(任务栏图标不消失)。 When I minimize the page1, it minimizes the application as expected but when I maximize the application from taskbar, I expect Page1 should maximizes but MainPage maximizes with an minimized Page one like below image.当我最小化 page1 时,它会按预期最小化应用程序,但是当我从任务栏最大化应用程序时,我希望 Page1 应该最大化,但 MainPage 会最大化,并使用最小化的第一个页面,如下图所示。

主页

I only want to correct these problems.我只想纠正这些问题。 I hope there is experts which experienced these things there.我希望那里有经历过这些事情的专家。

Problem is solved. 问题解决了。

The problem was, I was maximizing the form from properties of the page. 问题是,我正在根据页面的属性最大化表单。

Instead of maximizing it from properties, I do it manually from Page Load and its solved. 我没有从属性中最大化它,而是从Page Load及其解决方案中手动完成它。

this.Bounds = Screen.PrimaryScreen.WorkingArea;

In MetroFramework, I have the same problem.在 MetroFramework 中,我遇到了同样的问题。 When my application starts (in the FORM_LOAD), I programmatically maximize and the icon disappears.当我的应用程序启动时(在 FORM_LOAD 中),我以编程方式最大化并且图标消失了。 Checking the MetroFramework code, the problem is caused by ShadowType.检查 MetroFramework 代码,问题是由 ShadowType 引起的。 If you change the ShadowType to None:如果将 ShadowType 更改为 None:

this.ShadowType= MetroFormShadowType.None;

the issue is resolved.问题已解决。 I hope the solution works我希望解决方案有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM