Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Two taskbar icons appears while opening new form
 

Two taskbar icons appears while opening new form

Hi,

I am facing an issue of two-taskbar icon shown for windows application. I am using .Net 2.0

I am opening a new form using following code

Form frm = new Form();

frm.ShowDialog(this);

Now it shows two-taskbar icon Form1 and Form2. If we hide Form1 before opening the Form2 i.e.

Form frm = new Form();

Hide();

frm.ShowDialog(this);

Show();

Then only one icon is displayed in the taskbar with no icon in task manager. It also display two icon if your switch to some other application or minimize the current application while new form is getting opened(Add some delay while opening second form either in form constructor or form load event).

Can anyone suggest me the best approach for opening new form by hiding previous one with some sample example?

Asif Shaikh  Thursday, February 07, 2008 9:55 AM

How about something like this?

Code Snippet

partial class Form2 : Form

{

public Form2()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Form f = new Form();

f.ShowInTaskbar = false;

f.Show();

f.Resize += new EventHandler(f_Resize);

}

void f_Resize(object sender, EventArgs e)

{

Form f = sender as Form;

if (f.WindowState == FormWindowState.Minimized)

{

this.WindowState = FormWindowState.Minimized;

}

}

}

Zhi-Xin Ye  Wednesday, February 13, 2008 10:41 AM

You can set the ShowInTaskbarproperty to false to make the new form not showing in the taskbar.

Form f = new Form();
f.ShowInTaskbar = false;
f.ShowDialog(this);

Zhi-Xin Ye  Wednesday, February 13, 2008 8:13 AM

This approach does not work as desired. I have already tried this approach.

Using this approachtwo-taskbar icon problem is solved but an additional problem of screen minimization is introduced.

When we minimize the child window, the parent window is visible in background.

Asif Shaikh  Wednesday, February 13, 2008 9:01 AM

How about something like this?

Code Snippet

partial class Form2 : Form

{

public Form2()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Form f = new Form();

f.ShowInTaskbar = false;

f.Show();

f.Resize += new EventHandler(f_Resize);

}

void f_Resize(object sender, EventArgs e)

{

Form f = sender as Form;

if (f.WindowState == FormWindowState.Minimized)

{

this.WindowState = FormWindowState.Minimized;

}

}

}

Zhi-Xin Ye  Wednesday, February 13, 2008 10:41 AM

This approach has its own disadvantages

1. On minimizing child Form, parent Form is minimized but an addition icon appears at left bottom corner of screen.

2. Icon shown in taskbar belongs to parent Form. Therefore, after minimizing screen and clicking on this icon shows parent Form instead of child Form.

3. Even if we use this approach, we need to handle some addition events for resizing or moving parent Form on corresponding action taken on child Form i.e. if we move or resize child Form parent Form is visible in background therefore we needs to adjust its size and location.

4. Some code needs to be executed after closing child Form therefore f.Show() method cannot be used in this context. We can handle Form Closed event of child form. However, we are having around 10 buttons each opens a new Form therefore we need to handle Closed event for each of this Form.

Is there no straightforward method available to open a new form?

Asif Shaikh  Thursday, February 14, 2008 12:49 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGrid View
• namespace could not be found
• I want a ITXCO10.dll in WIN NT.
• How to setup connection string
• Animal Farm?
• Error when attempting to start terrarium for first time
• Inclusion of "content" files in build... HOWTO?
• Defect in MainForm.MainForm_Load()
• Movement in Terrarium
• AppUpdater and IIS6 problem