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. Visual Basic
  4. Changing the location of a form through code

Changing the location of a form through code

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 3 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.
  • D Offline
    D Offline
    Drew
    wrote on last edited by
    #1

    Similar to my last thread, I'd like to save the form location as well. In talking to another programmer, he said that it'd probably be a good idea to have some preventative measures (i.e.: making sure the program doesn't appear off-screen). Is there a good or bad way to do this?

    L 1 Reply Last reply
    0
    • D Drew

      Similar to my last thread, I'd like to save the form location as well. In talking to another programmer, he said that it'd probably be a good idea to have some preventative measures (i.e.: making sure the program doesn't appear off-screen). Is there a good or bad way to do this?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi again, Your earlier post was on size, and you can protect size with the Form.MinimumSize property (it will refuse a Size that is less than that); just give it a reasonable minimum with Visual Designer. You could also set a MaximumSize, but there is no need AFAIK. As far as location is concerned, if Form.StartPosition is not set to Manual, you have no control; and if it is, you are responsible; bad coordinates will be accepted but may put it off-screen. So you may want to validate them, by comparing with (0,0) and SystemInformation.PrimaryMonitorSize, assuming you only have one monitor. With multiple monitors it gets complex easily. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      D 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi again, Your earlier post was on size, and you can protect size with the Form.MinimumSize property (it will refuse a Size that is less than that); just give it a reasonable minimum with Visual Designer. You could also set a MaximumSize, but there is no need AFAIK. As far as location is concerned, if Form.StartPosition is not set to Manual, you have no control; and if it is, you are responsible; bad coordinates will be accepted but may put it off-screen. So you may want to validate them, by comparing with (0,0) and SystemInformation.PrimaryMonitorSize, assuming you only have one monitor. With multiple monitors it gets complex easily. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        D Offline
        D Offline
        Drew
        wrote on last edited by
        #3

        Unfortunately, 95% of the people that will be using this program have 2 or more monitors (yes some have 3 and 4). It may be in my best interests to leave location alone and let Windows handle that. Someday I'll figure it out...

        T L 2 Replies Last reply
        0
        • D Drew

          Unfortunately, 95% of the people that will be using this program have 2 or more monitors (yes some have 3 and 4). It may be in my best interests to leave location alone and let Windows handle that. Someday I'll figure it out...

          T Offline
          T Offline
          The ANZAC
          wrote on last edited by
          #4

          well you can save the location as a point value in your settings. my.settings.SaveLocation = my.settings.location where SaveLocation is your variable.

          Please check out my articles: The ANZAC's articles

          1 Reply Last reply
          0
          • D Drew

            Unfortunately, 95% of the people that will be using this program have 2 or more monitors (yes some have 3 and 4). It may be in my best interests to leave location alone and let Windows handle that. Someday I'll figure it out...

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            IIRC on a multi-monitor environment, Windows puts every Form on the "primary monitor" by default, and that might not be what you want. If the desktop got extended over all monitors (that's a checkbox per monitor), and if the monitors are arranged such that they (almost) cover a true rectangle, then it makes sense to validate a form's bounds (thats location+size) against SystemInformation.VirtualScreen You may want to have a closer look at the Rectangle type, in particular Rectangle.Contains(). If the desktop does not extend over all monitors, then I don't know how forms get positioned on those non-desktop monitors. Feel free to tell me more about that. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


            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