multiple screen management
multiple screen management
multiple screen management
multiple screen management
multiple screen management
multiple screen management multiple screen management multiple screen management multiple screen management multiple screen management multiple screen management multiple screen management multiple screen management
multiple screen management multiple screen management
multiple screen management
Go Back  Xtreme Visual Basic Talk > > > multiple screen management


Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2011, 09:52 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Question multiple screen management


In my project is a form called "Secondary". It is suppose to appear on any and all screens (if any) other than the primary screen. The following code seems pretty logical to me, but Secondary is not appearing on any screen.

Code:
    Private Sub ShowSecondary()
        Dim Extra_Screens As Screen
        Dim MySecondary As New Secondary
        For Each Extra_Screens In System.Windows.Forms.Screen.AllScreens
            If Extra_Screens IsNot Screen.PrimaryScreen Then
                MySecondary.Show()
                MySecondary.WindowState = FormWindowState.Maximized
            End If
        Next
    End Sub
I've also tried with "If Extra_Screens.Primary = False Then".
__________________
Amerigo

Last edited by Amerigo; 09-18-2011 at 10:05 PM.
Reply With Quote
  #2  
Old 09-18-2011, 10:53 PM
AtmaWeapon's Avatar
AtmaWeaponmultiple screen management AtmaWeapon is offline
Fabulous Florist

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

While it may seem so, Windows doesn't really have any concept of which screen a window is displayed on. Each screen gets allocated some coordinates in a big fat virtual space, and if your window's coordinates happen to fall within some monitor's space it's on that monitor.

Even if there were a magic interface to put your window on a particular screen, your code doesn't try. Here's what your code does:
Code:
* Create a new instance of the class Secondary.
* For each screen attached to the system:
    * If this screen is not the primary screen:
        * Show the Secondary instance at its default position.
        * Maximize the Secondary instance.
You're missing a "move the Secondary instance onto this screen" step. (You also do it for all monitors that aren't the primary, so it'd be unpredictable on a > 2 monitor system. I just said that kind of API doesn't exist, so you have to fudge it. Screen has a WorkingArea property that returns a Rectangle representing the available space on the screen. As long as you move a form's top-left corner into that coordinate space, maximizing the form ought to display it on that monitor. It'd look something like this:
Code:
For Each attachedScreen In Screen.AllScreens
    If attachedScreen IsNot Screen.PrimaryScreen Then
        Dim secondaryArea = attachedScreen.WorkingArea
        Dim secondary As New Secondary()
        secondary.Location = secondaryArea.Location
        secondary.Show()
    End If
Next
__________________
.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
  #3  
Old 09-18-2011, 11:47 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

Thank you! That worked like a charm.

Now, the problem is, I can't get all instances of "Secondary" to hide/close.
__________________
Amerigo

Last edited by Amerigo; 09-18-2011 at 11:52 PM.
Reply With Quote
  #4  
Old 09-19-2011, 06:16 AM
snarfblam's Avatar
snarfblammultiple screen management snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

You need to store a reference to all of the secondary forms. The easiest way to do this is to use a List(Of T). Declare this in the same class that creates the secondary forms, and every time you create a secondary form, add it to the list.
Code:
Dim SecondaryForms As New List(Of Secondary)

Sub Usage
    Dim mySecondary As New Secondary()
    ' Do stuff with the form

    SecondaryForms.Add(mySecondary)
End Sub
As long as you do this, you can access each secondary form. You'll probably want to make two functions (along the lines of ShowSecondaries and HideSecondaries), each of which can iterate SecondaryForms with a For Each loop to perform the appropriate action (Show or Hide) to each form.
__________________
C# _VB.NET _
Reply With Quote
  #5  
Old 09-19-2011, 06:24 AM
DrPunk's Avatar
DrPunkmultiple screen management DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

You could use Application.OpenForms and check the type of the form.

Code:
Dim f as Form
For Each f in Application.OpenForms
    if TypeOf f Is Secondary Then
        f.Close
    end if
next
__________________
There are no computers in heaven!
Reply With Quote
  #6  
Old 09-19-2011, 04:49 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

Thank you all for your help. With some guess work, I got Snarfblam's method to work with
Code:
    Private Sub HideSecondary()
        For Each MySecondary In SecondaryForms
            Close()
        Next
    End Sub
.
Dr. Punk's method removed any instance of Secondary just before giving an error @ 'Next'. Something getting stuck in the loop I guess.
__________________
Amerigo
Reply With Quote
  #7  
Old 09-20-2011, 03:09 AM
DrPunk's Avatar
DrPunkmultiple screen management DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Ooops. Sorry. Slipped my mind that you can't go deleting objects from the collection on a for each loop.

Code:
Dim i As Integer = 0

While i < Application.OpenForms.Count
    If TypeOf Application.OpenForms(i) Is Secondary Then
        Application.OpenForms(i).Close()
        ' If the form is closed then the same index i will point to the next form.
    Else
        ' If the form isn't closed then need to look at the next form.
        i += 1
    End If
End While
__________________
There are no computers in heaven!
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
multiple screen management
multiple screen management
multiple screen management multiple screen management
multiple screen management
multiple screen management
multiple screen management multiple screen management multiple screen management multiple screen management multiple screen management multiple screen management multiple screen management
multiple screen management
multiple screen management
 
multiple screen management
multiple screen management
 
-->