Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Form's Position changed after Show & Hide

Form's Position changed after Show & Hide

Scheduled Pinned Locked Moved C#
question
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yyf
    wrote on last edited by
    #1

    Hi, I use form.Hide() to hide a form, and use form.Show() to bring it back. However, I found that the form's position is changed. How did this happen? I didn't recreate this form, just hide and show again. How can I keep it as where it was? Thanks!

    Y 1 Reply Last reply
    0
    • Y yyf

      Hi, I use form.Hide() to hide a form, and use form.Show() to bring it back. However, I found that the form's position is changed. How did this happen? I didn't recreate this form, just hide and show again. How can I keep it as where it was? Thanks!

      Y Offline
      Y Offline
      yyf
      wrote on last edited by
      #2

      I found this from msdn about "Form.WindowState Property" Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. This is reflected in the Height, Left, Top, and Width property settings. If a form is hidden after it has been shown, these properties reflect the previous state until the form is shown again, regardless of any changes made to the WindowState property. I think this is the reason, my form keeps changing position. But How can I keep it stay where it was? Thanks in advance.

      E 1 Reply Last reply
      0
      • Y yyf

        I found this from msdn about "Form.WindowState Property" Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. This is reflected in the Height, Left, Top, and Width property settings. If a form is hidden after it has been shown, these properties reflect the previous state until the form is shown again, regardless of any changes made to the WindowState property. I think this is the reason, my form keeps changing position. But How can I keep it stay where it was? Thanks in advance.

        E Offline
        E Offline
        exhaulted
        wrote on last edited by
        #3

        You could set some variables to the co-ordinaets of your form when you hide it, then when you show it, re-set the form's position to those variables. i.e. Point loc = this.Location; this.Hide(); //Showing this.Show(); this.Location = loc; Not a great solution but would work till you can get a better one. Kev Robert E. Lee's Truce Judgement comes from experience; experience comes from poor judgement.

        Y 1 Reply Last reply
        0
        • E exhaulted

          You could set some variables to the co-ordinaets of your form when you hide it, then when you show it, re-set the form's position to those variables. i.e. Point loc = this.Location; this.Hide(); //Showing this.Show(); this.Location = loc; Not a great solution but would work till you can get a better one. Kev Robert E. Lee's Truce Judgement comes from experience; experience comes from poor judgement.

          Y Offline
          Y Offline
          yyf
          wrote on last edited by
          #4

          Thanks.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups