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. StartPosition=CenterParent doesn't work half the time

StartPosition=CenterParent doesn't work half the time

Scheduled Pinned Locked Moved C#
4 Posts 4 Posters 0 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.
  • E Offline
    E Offline
    elena12345
    wrote on last edited by
    #1

    The form I am dealing with pops up in the middle of the application only half time time. The other half the time it goes into the upper-left corner. If I set a break point inside the form to check what the parent is - it's always null. But it's null for all the forms in our app, yet this is the only form that is acting funky. I was wondering if anyone else ran into problems with setting StartPosition to CenterParent. Thanks, Elena

    L N 2 Replies Last reply
    0
    • E elena12345

      The form I am dealing with pops up in the middle of the application only half time time. The other half the time it goes into the upper-left corner. If I set a break point inside the form to check what the parent is - it's always null. But it's null for all the forms in our app, yet this is the only form that is acting funky. I was wondering if anyone else ran into problems with setting StartPosition to CenterParent. Thanks, Elena

      L Offline
      L Offline
      LongRange Shooter
      wrote on last edited by
      #2

      I have seen this. However I have not taken the time to determine what I'm doing when it works and what I'm doing when it does not work. (ie. form.Show() vs. form.ShowDialog()) This signature left intentionally blank

      1 Reply Last reply
      0
      • E elena12345

        The form I am dealing with pops up in the middle of the application only half time time. The other half the time it goes into the upper-left corner. If I set a break point inside the form to check what the parent is - it's always null. But it's null for all the forms in our app, yet this is the only form that is acting funky. I was wondering if anyone else ran into problems with setting StartPosition to CenterParent. Thanks, Elena

        N Offline
        N Offline
        Nick Parker
        wrote on last edited by
        #3

        elena12345 wrote: I was wondering if anyone else ran into problems with setting StartPosition to CenterParent You need to make sure your child form instance sets the it's Parent property before you display your form, that is assuming you are setting you StartPosition to CenterParent. If you don't have a parent, just set the StartPosition to CenterScreen to get the form centered on the screen. - Nick Parker
        My Blog | My Articles

        P 1 Reply Last reply
        0
        • N Nick Parker

          elena12345 wrote: I was wondering if anyone else ran into problems with setting StartPosition to CenterParent You need to make sure your child form instance sets the it's Parent property before you display your form, that is assuming you are setting you StartPosition to CenterParent. If you don't have a parent, just set the StartPosition to CenterScreen to get the form centered on the screen. - Nick Parker
          My Blog | My Articles

          P Offline
          P Offline
          partyganger
          wrote on last edited by
          #4

          Exactly. If you set the CenterParent property before the parent is known, it will have no effect. For instance If you set the CenterParent in the designer, it will be set when the constructor calls the designer generated code, at which point the parent is still unknown. The way to go here is either: Create a constructor that takes the parent form as a parameter, and then set the Parent property before calling the designer generated code Or: When you create the child form in the parent form, first set the Parent Property, then the StartPosition property and then call the Show(Dialog) method.

          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