Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Problem with Screen.AllScreens(0).DeviceName
I am having some problem with some code that worked OK when I programmed it on Vista 64 bit edition, but is having problems on a machine with Windows XP SP2. I have created some simple code that simulates the problem, rather than post my original code which is more complicated.
[code]'Obtain Monitor Name
Dim MonitorName As String = Screen.AllScreens(0).DeviceName
'Gets rid of the "\." at the start of the name
Do While MonitorName Like "**"
MonitorName = Microsoft.VisualBasic.Right(MonitorName, Len(MonitorName) - 1)
'Display message if Monitor Name is "DISPLAY1"
If (MonitorName = "DISPLAY1") Then
MsgBox("Monitor Found", MsgBoxStyle.OkOnly, "Monitor Search")
The problem is that the message box in the last line never displays, Even though the Monitorname is "DISPLAY1" As expected..
The problem seems to be coming from the call to "Screens.AllScreens(0).DeviceName in the first line. If I obtain the value of "DeviceName" by putting my cursor over this bit of code it says
DeviceName = "DISPLAY1
Notice how there is a quotation mark at the start and none at the end. This problem carries over to the MonitorName variable, and MonitorName would also be missing the final quotation mark when the If Statement is run.
I am programming with VB.Net Express 2008 edition. On a machine with Windows XP SP 2, and the program is using .Net Framework 2.0. I have tried switching to .Net Framework 3.0 without any success.
I suspect this is a bug with something on my machine, rather than with my program. Is there another way of obtaining the name of all monitors attached to the computer?