locked
When running a process then close the process the form1 in runtime dosent back to center of screen: RRS feed

  • Question

  • When i click the button the process is show up in the center of screen the form1 is moving to the right top corner and disabled thats working good as i want:

    if (processUnfreez == null || processUnfreez.HasExited)
                {
                    this.Size = new System.Drawing.Size(this.Size.Width / 2, this.Size.Height / 2);

                    this.Location = new Point(Screen.GetWorkingArea(this).Width - this.Width, 0);
                    this.Enabled = false;
                    processUnfreez = System.Diagnostics.Process.Start(Application.StartupPath + @"\UnFREEz.exe");
                    processUnfreez.WaitForInputIdle();
                    processUnfreez.Exited += new EventHandler(ProcessDone);
                    processUnfreez.EnableRaisingEvents = true;

                }

     

    The problem is in the ProcessDone event i tried so many things and couldnt bring back the form1 to his original size and to the center of screen enabled true.

    I tried this:

    rivate void ProcessDone(object sender, EventArgs e)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.Enabled = true;
                    this.WindowState = FormWindowState.Normal;
                    Rectangle screenbounds = Screen.GetWorkingArea(this);
                    this.StartPosition = FormStartPosition.CenterScreen;
                    this.BringToFront();
                    this.TopMost = true;
                });

     

    But then when i close the process and its doing the processdone the form1 in runtime is keep hanging on on the top right corner with small size just enabled true.

    Its never get back to the center of screen.

     

    Another problem i have is when i move drag the form1 in runtime around the screen to some location and minimize it from there when i resize back the form1 instead it will be resizing to the center of screen its resizing to where i minimized it from where i draged it from. If i drag it in runtime to the left top corner and minmize when ill maximize it back it will be in the top left corner and not in the center of screen.

     

    Thanks.

     

     


    danieli
    Monday, January 31, 2011 12:27 PM

Answers

  • Startup position only works when the application first launches.

    I would suggest capturing the X/Y positions on form_load (when the form is centered) then you can move the form to those positions at will.

    Adam


    Ctrl+Z
    • Marked as answer by chocolade Tuesday, February 1, 2011 12:13 PM
    Monday, January 31, 2011 1:19 PM
  • You don't want bringtofront...you want Me.TopMost = true

    Adam


    Ctrl+Z
    • Marked as answer by chocolade Tuesday, February 1, 2011 12:13 PM
    Monday, January 31, 2011 3:02 PM
  • You can use the Form_MouseEnter and Form_MouseLeave events.

    Adam


    Ctrl+Z
    • Marked as answer by chocolade Tuesday, February 1, 2011 12:13 PM
    Monday, January 31, 2011 3:43 PM

All replies

  • Startup position only works when the application first launches.

    I would suggest capturing the X/Y positions on form_load (when the form is centered) then you can move the form to those positions at will.

    Adam


    Ctrl+Z
    • Marked as answer by chocolade Tuesday, February 1, 2011 12:13 PM
    Monday, January 31, 2011 1:19 PM
  • OkThen i tried what you said and it is bringing the form1 to the center of screen but the form1 is on the background behind.

    I tried to add this.BringToFornt(); but it didnt work. As i close the process the form is gone and then i see it went behind the screen i was on.

    I dont understand why its not coming to the front and going to the back when closing it.

     

    private void ProcessDone(object sender, EventArgs e)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.Enabled = true;
                    this.Location = new Point(form1_location_on_x, form1_location_on_y);
                    this.Size = new System.Drawing.Size(this.Size.Width * 2, this.Size.Height * 2);
                });

            } 

     

     

    Any ideas why its not working why the form1 is going ot the back behind and the bringotfront dosent work?

     

    Thanks.

     

     

    Sunce it didnt work i tried to add some stuff in the processdone event but it dodnt work either:

    private void ProcessDone(object sender, EventArgs e)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.Enabled = true;
                    this.WindowState = FormWindowState.Normal;
                    this.Location = new Point(form1_location_on_x, form1_location_on_y);
                    this.Size = new System.Drawing.Size(this.Size.Width * 2, this.Size.Height * 2);
                    Rectangle screenbounds = Screen.GetWorkingArea(this);
                    this.BringToFront();
                });
            


    danieli
    Monday, January 31, 2011 2:43 PM
  • You don't want bringtofront...you want Me.TopMost = true

    Adam


    Ctrl+Z
    • Marked as answer by chocolade Tuesday, February 1, 2011 12:13 PM
    Monday, January 31, 2011 3:02 PM
  • Its working.

    But now when i close the process and the form1 is back to the center of screen wich is good.

    When i move with the mouse to another screen lets say i click on an opened InternetExplorer window the form1 is coming with me i mean he stay in the topmost.

    Is there anyway to tell him that if i click on another window out of the form1 so the topmost will be false or something?

     

    Thanks.

     


    danieli
    Monday, January 31, 2011 3:09 PM
  • You can use the Form_MouseEnter and Form_MouseLeave events.

    Adam


    Ctrl+Z
    • Marked as answer by chocolade Tuesday, February 1, 2011 12:13 PM
    Monday, January 31, 2011 3:43 PM