Results 1 to 16 of 16

Thread: Multiple Monitors launching

  1. #1

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Multiple Monitors launching

    Scenario: I have a dual-monitor setup. When I launch the main program, I need to make sure that it always launches in "Screen 1". I have a button within the program that launches another fullscreen window and I need this to always launch in the next available screen (read: not covering the main program window)

    I am using the System.Windows.Forms.Screen class to try to accomplish this and have have had about 80% success. I can successfully test for multiple monitors (which enables the button). When they click it, I can get it to always launch in the second screen. The problem I'm encountering while testing is the main program is launching in Screen 2, so the second window covers it.

    Here's what I'd like to accomplish ultimately: I would like to always launch my program in Maximized stated (and disable resizing, minimizing/maximizing is ok, just not double-clicking titlebar to resize) in the primary monitor (where Taskbar is being displayed). Then, when the button within the program is pressed, it launches the new window in the NEXT available monitor in Maximized stated.

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Multiple Monitors launching

    what happens if you set window2's location to:

    Code:
    window2.location = new point(window1.location.x + window1.size.width + 20,0)
    window2.state = maximized 'not the actual code
    window2.show()
    ?

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Multiple Monitors launching

    is there a way to test which screen a certain window resides in?

    like, if i used your code (which i haven't tested), if they have 2 monitors and they move the primary program window to the second monitor (on the right), then your code would put it to the right of that one, which would put it where a 3rd monitor WOULD be (off-screen basically)

    I need a way to test:

    pseudo:
    vb Code:
    1. Dim screen() As Screen = Screens.AllScreens
    2. if mainProgramWindow.Screen = screen(0) then 'This isn't testable from what I can see
    3.    secondProgramWindow.Screen = screen(1)
    4.    secondProgramWindow.Show
    5. Else
    6.    secondProgramWindow.Screen = screen(0)
    7.    secondProgramWindow.Show
    8. End if

  4. #4
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Multiple Monitors launching

    I think this would work:

    Code:
    screen = screen.AllScreens(0)
    isn't that the default monitor?

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  5. #5

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Multiple Monitors launching

    that would work for what? I already have that code.
    My application will always launch on whatever the primary monitor is. This is fine. I need a way to TEST what monitor it is displaying in though, as the primary monitor may be on the left, or it may be on the right. (in a 2 monitor setup)

    My project should be able to run on a limitless amount of monitors.

  6. #6
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Multiple Monitors launching

    Umm you can get the bounds of the screen?

    if you know what the x,y width and height of each screen is, you know where to put it.

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  7. #7

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Multiple Monitors launching

    having trouble getting my mind around this one.

    Let's assume i have 4 monitors (all the same size and resolution) *this will be a real scenario during testing*

    Let's also assume the far left monitor is the primary monitor and each consecutive monitor to the right of that is 2, 3, and 4 respectively.

    When I launch my program, I would expect it to show up in the far left monitor (easy enough). The "Spawn" button within my program should launch the next window in the second monitor. If I click it again, it should launch the next window in the 3rd monitor etc. (this should work regardless of number of monitors)

    Now, this is pretty easy to test for, I could capture the width and height of the primary screen and test whether my form's location is within these bounds. if so, launch it in the next available screen.

    ..ok, typing that out actually helped me think through this.

    It's weird though, my computer at work (2 monitors) performs differently. The monitor on the left displays "1" and the monitor on the right displays "2" when clicking "Identify" in Display Properties. However, when launching my program from within Visual Studio to test, it launches the program in the right monitor, monitor "2". This causes the spawned window to open up on top of it (because right now i hard-coded Screen(1).)

    How can I ensure that my program will ALWAYS open on the first AVAILABLE screen (not necessarily the furthest left or whatever)?

  8. #8
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Multiple Monitors launching

    Screen.Primary lets you know which is the main screen.

    if say your primary screen is at index... 2.. and you have 0 - 4 monitors in total.

    then you know that you have 2 to the left, and 2 to the right.

    so you could draw to screen at index 2 first, then 0,1,3,4.

    Just remember where the last form is loaded so you can reset your x,y to reuse that position.

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  9. #9

    Re: Multiple Monitors launching

    How can I ensure that my program will ALWAYS open on the first AVAILABLE screen (not necessarily the furthest left or whatever)?
    Wouldn't the System.Windows.Forms.Screen.AllScreens Class have anything you need?

  10. #10

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Multiple Monitors launching

    here's a screenshot of the application runnin on my dev environment. the right screen is my primary and it correctly spawns new window in the left monitor, not covering the primary.

    i'll look at that Screens.Primary property. I didn't see that one earlier.

    for argument's sake, how would i FORCE the main program to launch in a specific window? can this be set before the form is loaded or what event should this be set in?
    Attached Images Attached Images  

  11. #11
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Multiple Monitors launching

    You can always set the Location.X and Location.Y of the form before you show it.

    So you could just keep track of what monitors you use when you show them, and then remove that monitor from the 'remember' list when that form closes.

    so if the primary is avail. then you have only ran the main form, so set the x,y to that screen. else, find the first avail. monitor in the screen.allscreens, set the new spawn form's x,y = that screen, add that screen to your remember list so next time you'll go to the next avail. one.

    Justin
    Last edited by MonkOFox; May 16th, 2010 at 01:24 AM.
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  12. #12

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Multiple Monitors launching

    Quote Originally Posted by MonkOFox View Post
    You can always set the Location.X and Location.Y of the form before you show it.
    ahh that's what i'm trying to do, but doesn't seem to work in the Load Event. I'm not sure where I should actually put the code to set the X and Y prior to it being shown.

    The rest seems doable. I'll give it a shot.

  13. #13
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Multiple Monitors launching

    Yeah I didn't think about that. It will work for any new forms you create while the program is running, but IF the first form always pops up in the primary screen, then you're still good, just loop through the screens and if it hasn't been used yet, and isn't the primary, then you should be good.

    If that isn't the case, then you could probably do some logic location programming in the designer.vb of the application startup form, to ensure it gets loaded into the primary screen.

    Keep us posted, want to see if you get it working : ),

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  14. #14

    Re: Multiple Monitors launching

    Make sure you set the form's "StartPosition" to manual just in case.

  15. #15

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Multiple Monitors launching

    cool, you got me thinking in a different approach and here's what i'm doing:

    vb Code:
    1. 'Number of Monitors Client has connected
    2.     Dim myScreens() As Screen = Screen.AllScreens
    3.     Dim numScreens As Integer = myScreens.Length
    4.     Dim availableScreens As Integer = myScreens.Length

    Every time I call my "LaunchAnotherWindows" Sub, I subtract 1 as well. Here's that sub:

    vb Code:
    1. Public Sub LaunchInNewMonitor()
    2.         availableScreens -= 1
    3.  
    4.         'Set flag to show that multiple monitors are now being used
    5.         multipleMonitors = True
    6.  
    7.         'Create a New Parent Form
    8.         Dim secondScreenParent As New Form
    9.         'Set its Properties
    10.         With secondScreenParent
    11.             .ShowInTaskbar = True
    12.             .FormBorderStyle = Windows.Forms.FormBorderStyle.None
    13.             .Width = myScreens(numScreens - availableScreens).WorkingArea.Width
    14.             .Height = myScreens(numScreens - availableScreens).WorkingArea.Height
    15.             .IsMdiContainer = True
    16.             .StartPosition = FormStartPosition.Manual
    17.             .Location = myScreens(numScreens - availableScreens).Bounds.Location
    18.             .Show()
    19.         End With
    20.  
    21.         ShowCamerasForm(16, "00001", 1, secondScreenParent)
    22.     End Sub

    I'll add an addition statement in the closing event.
    I think this should work just fine! Im anxious to test it, but getting access to more than 2 monitors may prove to be difficult lol. It's working on 2 though!

    EDIT: removed the -1 from the main form load. it was throwing index out of range. i now disable the button once all screens are filled.

  16. #16
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Multiple Monitors launching

    Awesome man! Glad it's working for you : ). Theoretically (to me anyways) it should work on 2 monitors as well as 24.

    But you'll just have to test it on more than 2 to see the outcome.

    Grats again!

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width