0
votes

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. 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.

//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.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). 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.

MainPage

I only want to correct these problems. I hope there is experts which experienced these things there.

1
Dont hide the form! - BugFinder
There is another problem on that case. MainPage should be hidden for user experience. - Alexander Chef
Thats then a design issue - but the reason it goes from the bar is you are hiding the main form. - BugFinder
i suggest to use MDI forms How To USE it is a professional and pretty cool thing - Syed Muhammad Munis Ali
Thanks for your suggestion but as I can see MDI container opens the new form inside of the parent. This is not suitable for me. The pages are irrelevant. I think you suggest this with looking the image that I shared. The menu item is not exist at Page1 - Alexander Chef

1 Answers

0
votes

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.

this.Bounds = Screen.PrimaryScreen.WorkingArea;