|
-
Dec 16th, 2005, 07:33 PM
#1
Thread Starter
New Member
Does Screen class work with dual monitors?
I am creating a function in a core DLL that will compute the size a form object should be based on the screen resolution and required border, taking into consideration any taskbars, docked windows, etc...
I am using the System.Windows.Forms.Screen namespace.
My question is, will this name space only work on single monitor machines? If someone is using the application on a machine with dual monitors will it base the calculations using the resolution of the primary video card, or which ever screen the application is being displayed on.
Its confusing me because its pulling the information from the primary screen. So I'm assuming this function will not work on a machine running dual monitors. Unless all monitors are running the same resolution.
I would just test it, however I don't have access to a second monitor. I have included the code incase someone has a dual monitor machine they can run this on and see what happens.
Thanks Very Much!
Required Namespaces:
System.Windows.Forms
System.Drawing
Code:
/// <summary>
/// A basic function that decides where the form should be located on screen
/// based on the required border and the screen resolution. This is usually
/// used for main forms, such as the MDI object.
/// </summary>
/// <param name="verticalBorder">
/// The required vertical border (space between the edge of the screen and the form).
/// </param>
/// <param name="horizontalBorder">
/// The required horizontal border (space between the edge of the screen and the form).
/// </param>
/// <returns>
/// Returns the exact size of the form object, including the calculated borders.
/// </returns>
public static Size SetWindowSize(int verticalBorder, int horizontalBorder)
{
// Create the fields to store the border information.
int theHeight, theWidth;
// Compute the exact height and width of the form.
theHeight = Screen.PrimaryScreen.WorkingArea.Height - verticalBorder;
theWidth = Screen.PrimaryScreen.WorkingArea.Width - horizontalBorder;
// Return the new size to the calling function.
return new Size(theWidth, theHeight);
}
Code:
// Get the size for the form.
this.Size = common.SetWindowSize(10, 10);
this.CenterToScreen();
- Billiard
If you would like me to read your code, please use [code] tags.
-
Dec 18th, 2005, 09:04 AM
#2
Re: Does Screen class work with dual monitors?
It's not a namespace, it's a class. The PrimaryScreen property is, as the name suggests, a Screen object that represents the primary monitor. Given that the vast majority of users will only ever have one monitor it is quite logical that there would be a property specific to it. I suggest you read the help topics on the Screen class and its members. They have all the information you need. The help/MSDN really should be the first place you look for information like this, then look elsewhere if it doesn't have what you need or you can't understand what it says.
-
Dec 18th, 2005, 12:11 PM
#3
Thread Starter
New Member
Re: Does Screen class work with dual monitors?
 Originally Posted by jmcilhinney
It's not a namespace, it's a class. The PrimaryScreen property is, as the name suggests, a Screen object that represents the primary monitor. Given that the vast majority of users will only ever have one monitor it is quite logical that there would be a property specific to it. I suggest you read the help topics on the Screen class and its members. They have all the information you need. The help/MSDN really should be the first place you look for information like this, then look elsewhere if it doesn't have what you need or you can't understand what it says.
excuuuuuseeeeeeeeeeee ME could you please email my head back to me?
- Billiard
If you would like me to read your code, please use [code] tags.
-
Dec 18th, 2005, 07:37 PM
#4
Re: Does Screen class work with dual monitors?
 Originally Posted by Billiard
excuuuuuseeeeeeeeeeee ME could you please email my head back to me?
I'm not sure whether you're having a go at yourself or at me. 
The Screen class has a property named AllScreens that will give you an array of Screen objects. It also has methods to return the specific Screen object that contains the majority of a control, rectangle, object by handle or that contains a specific point. Once you have a Screen object you can then use its WorkingArea property as you have been. As an example, this:
VB Code:
Dim myScreen As Screen = Screen.PrimaryScreen
would have the same result as this:
VB Code:
Dim myScreen As Screen
For Each myScreen In Screen.AllScreens
If myScreen.Primary Then
Exit For
End If
Next myScreen
-
Dec 20th, 2005, 05:32 AM
#5
Re: Does Screen class work with dual monitors?
Or even
Code:
Screen myScreen = Screen.PrimaryScreen;
Code:
foreach (Screen myScreen in Screen.AllScreens)
{
if (myScreen.Primary)
break;
}
-
Dec 20th, 2005, 05:35 PM
#6
Re: Does Screen class work with dual monitors?
Possibly, but only for those who know where they are.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|