0

I'm making a multiform windows form application using C#, what I am trying to do is have a one notification icon, when pressed shows the active form ( the latest one that is open). so having notifyicon for every form is not the answer,

but having the same notifyicon means that I should handle the (clicked) event in the main forum only.

I'm not sure how to tackle this problem, if anyone can provide insight that would be great.

my existing code, which is applicable for the main page only.

    private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
    {

        if (this.WindowState == FormWindowState.Normal)
        {
            Show();
            this.Focus();

        }
        else if (this.WindowState == FormWindowState.Minimized)
        {
            Show();
            this.WindowState = FormWindowState.Normal;
            this.Focus();
        }
    }

Thanks and regards

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • Winforms by nature encourages a GUI model that real apps never actually use. Real apps always have a main window. If they create any additional ones then they are owned windows, not just random ones that float elsewhere and have no obvious connection to the main window with no decent way to get from one to the other. VS is a good example. Make your app behave like any real app you ever used before. And you automagically won't have this problem, you can always get back to that main window. – Hans Passant Nov 02 '17 at 22:27
  • Try [Form.ActiveForm](https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activeform(v=vs.110).aspx)? – Idle_Mind Nov 02 '17 at 23:09
  • Is this a MDI form with child forms in it? –  Nov 03 '17 at 03:47
  • @HansPassant , is such thing possible using windows forms ? – bahaeddin sagar Nov 04 '17 at 07:19
  • @Idle_Mind so instead of "this" it would be "form.activeform" ? I'll try that and let you know – bahaeddin sagar Nov 04 '17 at 07:20
  • @codemaker I didn't hear about MDI before, therefore I assume I am now using it. Could this solve the issue ? – bahaeddin sagar Nov 04 '17 at 07:26
  • [Here is an example of an MDI app](http://www.exforsys.com/images/vbnet/Lesson3_files/image040.jpg). If that is what you have then try [Form.ActiveMdiChild](https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activemdichild(v=vs.110).aspx). – Idle_Mind Nov 04 '17 at 14:32
  • well honestly ,, this is not the case, I'm not using MDI. Looks like I'll try to combine my forms in one Parent form to avoid this issue – bahaeddin sagar Nov 08 '17 at 15:39

0 Answers0