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. VB.NET form location

VB.NET form location

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
4 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.
  • J Offline
    J Offline
    Joe Surls
    wrote on last edited by
    #1

    I have a small application that I am running in the system tray using the NotifyIcon control. That functionality is working well. The form is set to Minimize initially and shown when the user clicks the tray icon. The problem is where the form displays. I want it to display in the lower right corner of the screen right above the system tray. Here is the code used to display the form: Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - Me.Width, My.Computer.Screen.WorkingArea.Height - Me.Height) End Sub I have also tried: Me.Left = SystemInformation.WorkingArea.Width - Me.Width Me.Top = SystemInformation.WorkingArea.Height - Me.Height I have tried both sets of code in both Activate and Form Load. Because of the "start minimized" nature of the app, initially both result in a Top and Left of -32000 because the form is not technically shown. At least that's my take. It's only off by half the form the FIRST time the form is shown and then it jumps to where I want it to be from then on. I've tried to show the form, then quickly hide it but this seems ridiculous. Does anyone have any suggestions? Thanks, Joe

    C 1 Reply Last reply
    0
    • J Joe Surls

      I have a small application that I am running in the system tray using the NotifyIcon control. That functionality is working well. The form is set to Minimize initially and shown when the user clicks the tray icon. The problem is where the form displays. I want it to display in the lower right corner of the screen right above the system tray. Here is the code used to display the form: Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - Me.Width, My.Computer.Screen.WorkingArea.Height - Me.Height) End Sub I have also tried: Me.Left = SystemInformation.WorkingArea.Width - Me.Width Me.Top = SystemInformation.WorkingArea.Height - Me.Height I have tried both sets of code in both Activate and Form Load. Because of the "start minimized" nature of the app, initially both result in a Top and Left of -32000 because the form is not technically shown. At least that's my take. It's only off by half the form the FIRST time the form is shown and then it jumps to where I want it to be from then on. I've tried to show the form, then quickly hide it but this seems ridiculous. Does anyone have any suggestions? Thanks, Joe

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Screens.PrimaryScreen might be what you need.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      J 1 Reply Last reply
      0
      • C Christian Graus

        Screens.PrimaryScreen might be what you need.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        J Offline
        J Offline
        Joe Surls
        wrote on last edited by
        #3

        I am correctly reading the size of the screen (only one in play, here). The actual assignment fails on initial load due to the minimized nature of the app. Once the form is fully shown, the properties are set correctly and, after that, it displays in the correct location. Joe

        H 1 Reply Last reply
        0
        • J Joe Surls

          I am correctly reading the size of the screen (only one in play, here). The actual assignment fails on initial load due to the minimized nature of the app. Once the form is fully shown, the properties are set correctly and, after that, it displays in the correct location. Joe

          H Offline
          H Offline
          Herl the Pearl
          wrote on last edited by
          #4

          Joe Surls wrote:

          Once the form is fully shown, the properties are set correctly and, after that, it displays in the correct location.

          Can't you just set the form's Visible property to False, then "show" it as you do now, and finally set the Visible property to True?

          Ask not whether it is useful. Ask what it is useful for.

          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