{c#} form's events question {intresting !}

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshaycjoshi
    New Member
    • Jan 2007
    • 153

    {c#} form's events question {intresting !}

    I am making on application which reduces to a NotifyIcon when minimised and again comes into existence when the NotifyIcon is double clicked.

    Here is the code that works
    Code:
    namespace formspractice
    {
        public partial class mainform : Form
        {
            public mainform()
            {
                InitializeComponent();
            }
    
            private void mainform_Resize(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    Hide();
                    notifyIcon.Visible = true;
                    notifyIcon.ShowBalloonTip(3);
                    
                }
    
            }
    
            private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                notifyIcon.Visible = false;
                Show();
                WindowState = FormWindowState.Normal;
    
    
    
            }
    
            private void mainform_FormClosing(object sender, FormClosingEventArgs e)
            {
                notifyIcon.Visible = false;
            }
    
    
        }
    }
    look at the series of calls in the Doubleclick event handler
    Show();
    WindowState = FormWindowState .Normal;


    if i change it to
    WindowState = FormWindowState .Normal;
    Show();


    Than i can see something maximizing but it's not showing.I guess it is not able to paint itself.

    Refresh() also not working
    Why is this ???
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I think you should set the WindowState before calling Show()

    Comment

    • akshaycjoshi
      New Member
      • Jan 2007
      • 153

      #3
      why is it so ?
      it's not working !

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Have you set a breakpoint and see where the code execution goes?
        It might be moving in a path you did not think it would go.

        Comment

        • akshaycjoshi
          New Member
          • Jan 2007
          • 153

          #5
          It is going exactly the way it should !
          I can see that form maximizing from the taskbar button but it's not showing as if it can not get painted.

          Comment

          • akshaycjoshi
            New Member
            • Jan 2007
            • 153

            #6
            If i make it maximised as
            Code:
                    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
                    {
                         this.WindowState = FormWindowState.Maximized;
                        notifyIcon1.Visible = false;
                        this.Show();
                   }
            Then it is showing !
            Last edited by Curtis Rutland; Dec 3 '08, 02:43 PM. Reason: Added Code Tags - Please surround your code with [CODE] and [/CODE]

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              So then it works ?

              Comment

              • akshaycjoshi
                New Member
                • Jan 2007
                • 153

                #8
                WindowState = FormWindowState .Normal; is still not working.
                But WindowState = FormWindowState .Maximised is working.

                (both done when we double click the notify icon)

                Plater why dont u do it urself, it's a short code.
                Maybe then u will have a better analysis of what is happening.

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  Just did and it works fine for me

                  Comment

                  • akshaycjoshi
                    New Member
                    • Jan 2007
                    • 153

                    #10
                    Please post your entire code

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      I am thinking in your case the window is being restored, but being restored "under" any other windows you have oppened.
                      I made the changes to force it to reshow on top.

                      [code=c#]
                      private void MainWindow_Resi ze(object sender, EventArgs e)
                      {
                      if (this.WindowSta te == FormWindowState .Minimized)
                      {
                      this.Visible = false;
                      }
                      }
                      private void ni1_MouseDouble Click(object sender, MouseEventArgs e)
                      {
                      if (e.Button == MouseButtons.Le ft)
                      {
                      this.Visible = true;
                      //These lines are used to make sure you window restores over other windows
                      this.TopMost = true;
                      Application.DoE vents();
                      this.TopMost = false;
                      //
                      this.WindowStat e = FormWindowState .Normal;
                      }
                      }
                      [/code]

                      Comment

                      • akshaycjoshi
                        New Member
                        • Jan 2007
                        • 153

                        #12
                        what do u mean by "under" any other windows ?

                        Comment

                        • Plater
                          Recognized Expert Expert
                          • Apr 2007
                          • 7872

                          #13
                          If you have other windows open when you restore the window (set visible=true and the window state = normal) it will often appear to have shown and then hide itself again.
                          What really happened was the window was drawn, then moved behind whatever other windows might have the focus.
                          If you minimize every single window you have, then double click your notifiy icon, you should see your window popup, but NOT have the focus.

                          Comment

                          • Curtis Rutland
                            Recognized Expert Specialist
                            • Apr 2008
                            • 3264

                            #14
                            Does toggling the TopMost property back and forth like that always bring the form to the front and let it keep the focus?

                            I have been using the Win32 API to do that:
                            Code:
                            [DllImport("user32.dll")]
                            [return: MarshalAs(UnmanagedType.Bool)]
                            private static extern bool SetForegroundWindow(IntPtr hWnd);
                            ......
                            SetForegroundWindow(this.Handle);
                            But if your way works, that seems to be less work.

                            Comment

                            • akshaycjoshi
                              New Member
                              • Jan 2007
                              • 153

                              #15
                              so why it is working without such "settings" when I do
                              this.WindowStat e = FormWindowState .Maximized; ?

                              I mean I dont have to toggle it then.

                              Comment

                              Working...