-1

I'm working on a C# Windows Forms application with multiple forms and a tray icon.

When my application starts, it adds a tray icon to systemtray, if i show a subform using .ShowDialog I get a new Instance of my application with a second tray Icon. Here is my code to show the subform:

    btnEditor_Click(object sender, EventArgs e) 
    {   
    CSV_Editor editor = new CSV_Editor(listEntrys,conf); 
    editor.ShowDialog(); 
    }

Both forms are winforms and only the mainform has a trayicon.

How to avoid getting two Icons?

Thanks for your help!

webhead
  • 1
  • 1
  • Is the "subform" of the same type as the main form? If not, does it also have a `NotifyIcon`? Please include the code you use to show the second form. – 41686d6564 stands w. Palestine Jul 07 '18 at 14:02
  • I included my code and other details in the Question. – webhead Jul 08 '18 at 09:55
  • That's not what I asked. Are both forms of the same type (`CSV_Editor`)? Also, how are you using/showing the "tray icon"? Are you using a `NotifyIcon`? If the second form is a different type, are you sure it doesn't have one as well? – 41686d6564 stands w. Palestine Jul 08 '18 at 12:21
  • No, the forms are from different type. I use a `NotifyIcon` (just dragged it from toolbox to my form). The `CSV_Editor` form has no `NotifyIcon` – webhead Jul 08 '18 at 12:38
  • In this case, you're not providing us with enough info to figure out what the problem is. My advice to you: Start a new application with two forms, put a `NotifyIcon` component on Form1 and have a method that calls `Form2Instance.ShowDialog()`, it should only display one tray icon, once you have that confirmed, start checking what additional code you have in the original application that might be causing the problem. If you're still not sure, you can edit the question again providing us with a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – 41686d6564 stands w. Palestine Jul 08 '18 at 12:49
  • I believe this other question and answer will address your problem and provide a solution: https://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-application – P. Roe Jul 13 '18 at 17:36

1 Answers1

0

Set ShowInTaskbar in your 2nd form to false.