Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application
Control multiple monitors from my application Control multiple monitors from my application
Control multiple monitors from my application
Go Back  Xtreme Visual Basic Talk > > > Control multiple monitors from my application


Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2009, 07:25 PM
ilimax ilimax is offline
Junior Contributor
 
Join Date: Nov 2003
Posts: 252
Default Control multiple monitors from my application


I have build custome windows in my application with cust contorl box on the top right corner. Minimimize, maximaize and close button are made by me.
I want to make another button beside that one which will control displaing of windows in multiple monitors environment. So, cllick on that button will list monitors and I send that window to second monitor.

Does anobody have idea how to make that in vb.net?
Reply With Quote
  #2  
Old 08-14-2009, 09:34 AM
rdcloud rdcloud is offline
Newcomer
 
Join Date: Mar 2009
Location: Oklahoma, USA
Posts: 11
Cool Dual monitors

Yes, I have an application that needs to start on the 'second' monitor (if there is one). So, in answer to your question... there is a way to detect if there is a secondary monitor.

In essence: once detected, you'd determine what it's x,y is and then set the form you want to display's location to that x,y (i'd also suggest you set the form's property of 'StartPosition' to "Manual".

here's the snippet it use(got it from another forum):

For Each secondaryScreen In Screen.AllScreens
If Not secondaryScreen.Primary Then Exit For
Next

' Use the primary screen if there is no secondary screen
If secondaryScreen Is Nothing Then
secondaryScreen = Screen.PrimaryScreen()
End If
' Move the form to the secondary screen
' Set the x,y to the selected screen(primary or secondary)
Screen_Position.Location = secondaryScreen.Bounds.Location
width = secondaryScreen.Bounds.Width
height = secondaryScreen.Bounds.Height

I save the width/height as my app 'must' use 1024/768.

It shouldn't be to difficult to have a form pop-up that checks this, if you want to give the user the option to choose.


Hope this works for you...
Reply With Quote
  #3  
Old 08-14-2009, 12:25 PM
AtmaWeapon's Avatar
AtmaWeaponControl multiple monitors from my application AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

That code's a relatively OK demo for putting the window on anything but the primary screen (there's some coding practices in it that are kind of odd) but it's not really what the OP wants. It sounds like he wants to cycle between several monitors if they're available.

This is actually more complicated than you might think, depending on your requirements. Here's a list of different things you might be asking for, in order of difficulty:
  1. Move to some other monitor in such a way that if you click the button multiple times you will always cycle through each monitor and end up back where you started.
  2. Same as 1, but realize that not all monitors are the same size. Always ensure the form's top left corner is on the monitor. (Technically if you don't do this, 1 will have bugs.)
  3. Same as 2, but you resize the form so that it will fit if it's too big for the monitor.
  4. Same as 2, but you resize the form so it fills the same ratio of the screen as it did on the last monitor.
  5. Same as 4, but you maintain a list of sizes and locations for each monitor so when you return to the original monitor the form is at the original location with the original size.
  6. You'd like to move to a specific monitor, for example, "move left" takes you from a monitor on the right to a monitor on the left.
  7. Same as 2-5, but using 6 as a reference point instead of 1.

The code below handles case 3 on the list above in a ham-fisted manner. In production code, I'd refactor this into several method calls and use a few more temporary variables, but this is what I felt was one of the more clear ways to express the idea:
Code:
    Private Sub MoveToNextMonitor()
        Dim screens() As Screen = Screen.AllScreens

        ' Get the current screen and its location in the list of screens
        Dim currentScreen As Screen = Screen.FromControl(Me)
        Dim currentScreenIndex As Integer = Array.IndexOf(screens, currentScreen)

        ' Get the index of the next screen
        Dim nextScreenIndex As Integer = currentScreenIndex + 1
        If nextScreenIndex = screens.Length Then
            nextScreenIndex = 0
        End If

        ' Get the location of the window relative to the top-left corner of the current screen
        Dim locationInScreenCoordinates As New Point()
        locationInScreenCoordinates.X = Location.X - currentScreen.Bounds.X
        locationInScreenCoordinates.Y = Location.Y - currentScreen.Bounds.Y

        ' Get the location of an equivalent point on the next screen
        Dim nextScreen As Screen = screens(nextScreenIndex)
        Dim newLocation As New Point()
        newLocation.X = nextScreen.Bounds.X + locationInScreenCoordinates.X
        newLocation.Y = nextScreen.Bounds.Y + locationInScreenCoordinates.Y

        ' If the window falls outside the bounds of the next screen, move the window so that it
        ' falls within the bounds of the screen.
        If Not nextScreen.Bounds.Contains(newLocation) Then
            If nextScreen.Bounds.Right < newLocation.X Then
                newLocation.X = nextScreen.Bounds.Right - Width
            ElseIf newLocation.X < nextScreen.Bounds.Left Then
                newLocation.X = nextScreen.Bounds.Left
            End If

            If newLocation.Y < nextScreen.Bounds.Top Then
                newLocation.Y = nextScreen.Bounds.Top
            ElseIf nextScreen.Bounds.Bottom < newLocation.Y Then
                newLocation.Y = nextScreen.Bounds.Bottom - Height
            End If
        End If

        ' If the window is larger than the screen, make it fit.
        If Width > nextScreen.Bounds.Width Then
            Width = nextScreen.Bounds.Width
        End If

        If Height > nextScreen.Bounds.Height Then
            Height = nextScreen.Bounds.Height
        End If

        ' Place the window
        Me.Location = newLocation
    End Sub
Handling case 6 and its variants involves a grasp of geometry. For example, if the user chooses "move up", you'll first look for a monitor with the closest Bottom to the current screen's Top. Then, you have to compare Left and Right of both monitors to determine if they have a vertical relationship (this is necessary because a > 2-monitor configuration might have corner relationships, so a monitor can be "up and to the left" or "up and to the right".) Finally, if more than one candidate exists (a Y-layout might prove difficult), you have to break the tie in some deterministic fashion.

There's no simple way to handle multiple monitors properly, but if you put your head to the geometry it's not too tough to understand the issues.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application Control multiple monitors from my application
Control multiple monitors from my application
Control multiple monitors from my application
 
Control multiple monitors from my application
Control multiple monitors from my application
 
-->