הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, October 7, 2006 7:34 AM
Hi,
I'm experimenting with dual monitors and VB .net 2003. (I'm pretty new to the language... sorry if the question is lame)
I've been tinkering with System.Windows.Forms.Screen.AllScreens and can get screen information (device names, bounds, working area, etc..)
Can anyone offer a simple example of opening a form on a secondary monitor from the primary screen?
If i can get this then I should be fine with what I am trying to accomplish.
Any help is appreciated.
Thanks!
All replies (12)
Saturday, October 7, 2006 8:12 AM ✅Answered | 7 votes
All you need to do to show a form on a specifi screen is to set its Location property so it is in the specified screen Bounds:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form As New Form
Dim screen As Screen
' We want to display a form on screen 1
screen = screen.AllScreens(1)
' Set the StartPosition to Manual otherwise the system will assign an automatic start position
form.StartPosition = FormStartPosition.Manual
' Set the form location so it appears at Location (100, 100) on the screen 1
form.Location = screen.Bounds.Location + new Point(100, 100)
' Show the form
form.ShowDialog(Me)
End Sub
Saturday, October 7, 2006 8:10 AM
Hi,
You can use the WorkingArea property of the Screen object. Here's an example (not tested):
Dim myScreens() As Screen = Screen.AllScreens
If (myScreens.Length = 2) Then'Position form 1 in the middle of screen 1
Me.Left = myScreens(0).WorkingArea.Width / 2 - Me.Width / 2
Me.Top = myScreens(0).WorkingArea.Height / 2 - Me.Height / 2'Position the top left corner of form 2 in the middle of screen 2
Dim myForm2 As New Form2
myForm2.Show()
myForm2.Left = myScreens(0).Bounds.Width + myScreens(1).WorkingArea.Width / 2
myForm2.Top = myScreens(1).WorkingArea.Height / 2
End If
Hope this helps,
Tuesday, October 10, 2006 11:07 AM
Thanks for the help here.
It's exactly what i was after.
Tuesday, October 10, 2006 11:27 AM
FYI, please note that the bounds property of the screen object is the entire screen, while the workingarea is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.
Placing a form within the bounds of a screen, might hide portions of it behind a taskbar or docked window.
Regards,
Tuesday, January 8, 2008 6:34 AM
Hi,
Is it possible to get monitor information of some other machine? In particular, I want to know how many monitors are connected to some other machine.
Friday, January 25, 2008 4:21 PM
hello all i seem to be having an issue querying attached display devices ...
i have a GeForce 7900GT 256MB 256-bit GDDR3 PCI Express x16 and a 42" Panasonic 720p HD TV
only my monitor ( 22" Gateway Flat Panel ) shows up in Screen.AllScreens
I'm connected to my gateway monitor via the dvi1 port on the video card, then a dvi - vga connector that goes into a kvm switch to share the monitor between 2 computers.
The TV is connected to the dvi2 port on the video card and a dvi-hdmi cable is used to connect it to the tv.
I can see the TV in the display properties and set it up to clone the screen or make it horiz / vert spread etc,
but when I'm in my app, I can't seem to get it to show up in the AllScreens collection.
As I'm writing, I'm going to try and set up the tv as the primary display and see if it finds it in the collection then.
Also I'll try without the KVM switch. (Funny what you think of when youo're not around to try it)
Until I get home tonight to try any ideas?
Monday, January 28, 2008 7:36 AM
well to much dismay i was unable to successfully connect both displays how i wanted ... my flat screen has the resolution of 1680*1050 while my tv's a 1280*120 hdtv ... when both resoltions are configured my flat screen becomes pink and distorted @ 720 instead of keeping its 1680*1050 resolution. I don't think a stretch is possible like that but i wanted to do a clone or something. I want to display two different things on two different displays.
Thursday, February 7, 2008 12:59 AM
Hi Mark,
Connection problems are a little bit off-topic here.
Still, from my experience on other formus, Panasonic TVs seem to have some issues when connected to PC.
Of course, I know you got the latest drivers for your graphic card and the cables are OK. (EDID data flows from one end to another so you can actually see the name of the monitor and TV on PC)
If you have enough info about your hardware, you may try PowerStrip which will alow you to manually configure all the frequences and timings.
Good luck!
And now, my question:
System.Windows.Forms.Screen.AllScreens enumeration seem to contain a virtual display also.
How can I avoid it?
I've tested this on two different computers (VB.Net 2005, XP Professional SP2, .Net Framework 2.0):
The first - PC with XP Profi SP2, ATI graphics card, two monitors (HERCULES PROPHETVIEW on VGA, default monitor, and SAMSUNG LE40M86 on DVI - secondary monitor)
The second - DELL laptop with XP Profi SP2, (default monitor, Intel 915 graphics chip)
In first case, the enumeration contains 3 monitors DISPLAY1, DISPLAY2 and DISPLAYV2:
(0) {Bounds = {Primary = True DeviceName = "\.\DISPLAY1} (bounds = 1280x1024 working area = 1280x994)
(1) {Bounds = {Primary = False DeviceName = "\.\DISPLAY2} (bounds = -1920x1080 w.a. = -1920x1080)
(2) {Bounds = {Primary = False DeviceName = "\.\DISPLAYV2} (bounds = 1280x1024 w.a. = 1280x1024)
Here, "DisplayV2" is in fact Display1 BUT its working area doesn't exclude the taskbar(!!!)
In the second case, primary DISPLAY1 is also accompanied by a secondary "DISPLAYV1", also ignoring the taskbar...
Any clues where do these virtual display came from?
Thanks.
Mircea.
Thursday, July 3, 2008 12:19 PM
hi,
try this
form.StartPosition := dotNET.System_Windows_Forms.FormStartPosition.CenterScreen;
:)
Attitude
Tuesday, October 28, 2008 4:12 PM
Mark-New Hudson Technologies,LLC said:
hello all i seem to be having an issue querying attached display devices ...
i have a GeForce 7900GT 256MB 256-bit GDDR3 PCI Express x16 and a 42" Panasonic 720p HD TV
only my monitor ( 22" Gateway Flat Panel ) shows up in Screen.AllScreens
I'm connected to my gateway monitor via the dvi1 port on the video card, then a dvi - vga connector that goes into a kvm switch to share the monitor between 2 computers.
The TV is connected to the dvi2 port on the video card and a dvi-hdmi cable is used to connect it to the tv.
I can see the TV in the display properties and set it up to clone the screen or make it horiz / vert spread etc,
but when I'm in my app, I can't seem to get it to show up in the AllScreens collection.
As I'm writing, I'm going to try and set up the tv as the primary display and see if it finds it in the collection then.
Also I'll try without the KVM switch. (Funny what you think of when youo're not around to try it)
Until I get home tonight to try any ideas?
I just have to comment on this because it is something so typically simple.
If you set your screen to CLONE or Vert/horizontal span you only have ONE screen.
A clone is one screen copied to another display device.
A vert/horizontal span is also ONE screen with a virtual (combined) resolution of the two screens.
ONLY dualview will give you what you are looking for in the Screen.AllScreens array.
However, you can most likely find out what ACTUAL devices are connected and their respective settings, but the screen object handles the virtual "desktops" created AFTER the device settings/capabilities. This is how windows operate and this is what is given to you through the screen object.
Don't ask me how to enumerate the devices, i have no clue mmkay?
//Cadde
Tuesday, October 28, 2008 4:32 PM
Hi ALL,
While on the subject of DUAL screen setups some of you might like to try this software which will let you use another PC ( say a laptop ) as a 2nd monitor. :-)
Before you ask I do not work for this company either.>>
Regards,
John
For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
Saturday, March 24, 2018 11:17 AM
This is worked fine until I put video player on form2.
if i put full screen image its works. but i want to show some video on second screen.
if i try to add windows media player on form2 then its not opening on 2nd screen. its just open in first screen.
Could you help me with this?