Question Setting Primary Display

Jayme65

Active member
Joined
Apr 5, 2011
Messages
35
Programming Experience
Beginner
Hi,
I'm trying to set the Primary Display...without success!
Here's the code I'm working on, would you please help me see what I'm doing wrong there?
There's no compilation error...it simply doesn't give the expected result!
Thank you!!

VB.NET:
[COLOR=#0000ff]Imports[/COLOR] System.Runtime.InteropServices
[COLOR=#0000ff]Class[/COLOR] MainWindow
    [COLOR=#0000ff]Const[/COLOR] CCDEVICENAME [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR] = [COLOR=#cc66cc]32[/COLOR]
    [COLOR=#0000ff]Const[/COLOR] CCFORMNAME [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR] = [COLOR=#cc66cc]32[/COLOR]
 
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] MONITORINFOF_PRIMARY [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H1
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DISPLAY_DEVICE_ATTACHED_TO_DESKTOP [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H1
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DISPLAY_DEVICE_PRIMARY_DEVICE [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H4
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DISPLAY_DEVICE_MIRRORING_DRIVER [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H8
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DISPLAY_DEVICE_VGA_COMPATIBLE [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H10
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DISPLAY_DEVICE_REMOVABLE [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H20
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DISPLAY_DEVICE_MODESPRUNED [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H8000000
 
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DM_POSITION = &H20
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DM_DISPLAYORIENTATION = &H80 [COLOR=#808080]' XP only[/COLOR]
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DM_BITSPERPEL = &H40000
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DM_PELSWIDTH = &H80000
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DM_PELSHEIGHT = &H100000
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DM_DISPLAYFLAGS = &H200000
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] DM_DISPLAYFREQUENCY = &H400000
    [COLOR=#808080]'Private Const DM_DISPLAYFIXEDOUTPUT As Long = &H20000000 ' XP only[/COLOR]
 
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] ENUM_CURRENT_SETTINGS [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = -[COLOR=#cc66cc]1[/COLOR]
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] ENUM_REGISTRY_SETTINGS [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = -[COLOR=#cc66cc]2[/COLOR]
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] EDS_RAWMODE [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H2
 
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_UPDATEREGISTRY [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H1
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_TEST [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H2
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_FULLSCREEN [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H4
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_GLOBAL [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H8
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_SET_PRIMARY [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H10
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_VIDEOPARAMETERS [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H20
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_NORESET [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H10000000
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_RESET [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H40000000
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_FORCE [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = &H80000000
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Const[/COLOR] CDS_NONE [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = [COLOR=#cc66cc]0[/COLOR]
 
    [COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Structure[/COLOR] PointL
        [COLOR=#0000ff]Dim[/COLOR] x [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Dim[/COLOR] y [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Structure[/COLOR]
 
    <Flags()> _
    [COLOR=#0000ff]Enum[/COLOR] DisplayDeviceStateFlags [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        AttachedToDesktop = &H1
        MultiDriver = &H2
        PrimaryDevice = &H4
        MirroringDriver = &H8
        VGACompatible = &H10
        Removable = &H20
        ModesPruned = &H8000000
        Remote = &H4000000
        Disconnect = &H2000000
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Enum[/COLOR]
 
    [COLOR=#808080]'0 is Not Attached[/COLOR]
 
    [COLOR=#0000ff]Const[/COLOR] DISPLAY_PRIMARY_DEVICE = &H4 [COLOR=#808080]'Primary device[/COLOR]
 
    [COLOR=#808080]'Holds the information of display adpter[/COLOR]
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Structure[/COLOR] DISPLAY_DEVICE
        [COLOR=#0000ff]Public[/COLOR] cb [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> [COLOR=#0000ff]Public[/COLOR] DeviceName [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR]
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=[COLOR=#cc66cc]128[/COLOR])> [COLOR=#0000ff]Public[/COLOR] DeviceString [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] StateFlags [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=[COLOR=#cc66cc]128[/COLOR])> [COLOR=#0000ff]Public[/COLOR] DeviceID [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR]
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=[COLOR=#cc66cc]128[/COLOR])> [COLOR=#0000ff]Public[/COLOR] DeviceKey [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR]
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Structure[/COLOR]
 
    [COLOR=#808080]'Holds the setting of display adapter[/COLOR]
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Structure[/COLOR] DEVMODE
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
        [COLOR=#0000ff]Public[/COLOR] dmDeviceName [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmSpecVersion [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmDriverVersion [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmSize [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmDriverExtra [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmFields [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmOrientation [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#808080]'Public dmPaperSize As Short[/COLOR]
        [COLOR=#808080]'Public dmPaperLength As Short[/COLOR]
        [COLOR=#808080]'Public dmPaperWidth As Short[/COLOR]
        [COLOR=#808080]'Public dmScale As Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmPositionX [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmPositionY [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmCopies [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmDefaultSource [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmPrintQuality [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmColor [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmDuplex [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmYResolution [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmTTOption [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmCollate [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> _
        [COLOR=#0000ff]Public[/COLOR] dmFormName [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmLogPixels [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmBitsPerPel [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmPelsWidth [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmPelsHeight [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmDisplayFlags [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmDisplayFrequency [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmICMMethod [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmICMIntent [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmMediaType [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmDitherType [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmReserved1 [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmReserved2 [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmPanningWidth [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#0000ff]Public[/COLOR] dmPanningHeight [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
        [COLOR=#808080]'Public dmPosition As Point[/COLOR]
        [COLOR=#808080]'Public dmPositionX As Integer[/COLOR]
        [COLOR=#808080]'Public dmPositionY As Integer[/COLOR]
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Structure[/COLOR]
 
    [COLOR=#808080]'API declaration set or get display adpter information[/COLOR]
    <DllImport([COLOR=#ff0000]"user32.dll"[/COLOR])> _
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Shared[/COLOR] [COLOR=#0000ff]Function[/COLOR] EnumDisplayDevices([COLOR=#0000ff]ByVal[/COLOR] Unused [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], _
    [COLOR=#0000ff]ByVal[/COLOR] iDevNum [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Short[/COLOR], [COLOR=#0000ff]ByRef[/COLOR] lpDisplayDevice [COLOR=#0000ff]As[/COLOR] DISPLAY_DEVICE, [COLOR=#0000ff]ByVal[/COLOR] dwFlags [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]) [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Function[/COLOR]
 
    <DllImport([COLOR=#ff0000]"user32.dll"[/COLOR])> _
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Shared[/COLOR] [COLOR=#0000ff]Function[/COLOR] EnumDisplaySettings([COLOR=#0000ff]ByVal[/COLOR] lpszDeviceName [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR], _
    [COLOR=#0000ff]ByVal[/COLOR] iModeNum [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByRef[/COLOR] lpDevMode [COLOR=#0000ff]As[/COLOR] DEVMODE) [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Function[/COLOR]
 
    <DllImport([COLOR=#ff0000]"user32.dll"[/COLOR])> _
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Shared[/COLOR] [COLOR=#0000ff]Function[/COLOR] ChangeDisplaySettingsEx([COLOR=#0000ff]ByVal[/COLOR] lpszDeviceName [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR], _
    [COLOR=#0000ff]ByRef[/COLOR] lpDevMode [COLOR=#0000ff]As[/COLOR] DEVMODE, [COLOR=#0000ff]ByVal[/COLOR] hWnd [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] dwFlags [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], _
    [COLOR=#0000ff]ByVal[/COLOR] lParam [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]) [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Function[/COLOR]
    <DllImport([COLOR=#ff0000]"user32.dll"[/COLOR])> _
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Shared[/COLOR] [COLOR=#0000ff]Function[/COLOR] ChangeDisplaySettingsEx([COLOR=#0000ff]ByVal[/COLOR] lpszDeviceName [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR], _
    [COLOR=#0000ff]ByRef[/COLOR] lpDevMode [COLOR=#0000ff]As[/COLOR] IntPtr, [COLOR=#0000ff]ByVal[/COLOR] hWnd [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] dwFlags [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], _
    [COLOR=#0000ff]ByVal[/COLOR] lParam [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]) [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Function[/COLOR]
 
[COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Sub[/COLOR] SetAsPrimaryMonitor(id [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]UInteger[/COLOR])
        [COLOR=#0000ff]Dim[/COLOR] device = [COLOR=#0000ff]New[/COLOR] DISPLAY_DEVICE()
        [COLOR=#0000ff]Dim[/COLOR] deviceMode = [COLOR=#0000ff]New[/COLOR] DEVMODE()
        device.cb = Marshal.SizeOf(device)
 
        EnumDisplayDevices([COLOR=#0000ff]Nothing[/COLOR], id, device, [COLOR=#cc66cc]0[/COLOR])
        EnumDisplaySettings(device.DeviceName, -[COLOR=#cc66cc]1[/COLOR], deviceMode)
        [COLOR=#0000ff]Dim[/COLOR] offsetx = deviceMode.dmPositionX
        [COLOR=#0000ff]Dim[/COLOR] offsety = deviceMode.dmPositionY
        deviceMode.dmPositionX = [COLOR=#cc66cc]0[/COLOR]
        deviceMode.dmPositionY = [COLOR=#cc66cc]0[/COLOR]
 
        ChangeDisplaySettingsEx(device.DeviceName, deviceMode, [COLOR=#cc66cc]0[/COLOR], (CDS_SET_PRIMARY [COLOR=#0000ff]Or[/COLOR] CDS_UPDATEREGISTRY [COLOR=#0000ff]Or[/COLOR] CDS_NORESET), [COLOR=#cc66cc]0[/COLOR])
 
        device = [COLOR=#0000ff]New[/COLOR] DISPLAY_DEVICE()
        device.cb = Marshal.SizeOf(device)
 
        [COLOR=#808080]' Update remaining devices[/COLOR]
        [COLOR=#0000ff]Dim[/COLOR] otherid [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]UInteger[/COLOR] = [COLOR=#cc66cc]0[/COLOR]
        [COLOR=#0000ff]While[/COLOR] EnumDisplayDevices([COLOR=#0000ff]Nothing[/COLOR], otherid, device, [COLOR=#cc66cc]0[/COLOR])
 
            [COLOR=#0000ff]If[/COLOR] device.StateFlags = DisplayDeviceStateFlags.AttachedToDesktop [COLOR=#0000ff]AndAlso[/COLOR] otherid <> id [COLOR=#0000ff]Then[/COLOR]
                device.cb = Marshal.SizeOf(device)
                [COLOR=#0000ff]Dim[/COLOR] otherDeviceMode = [COLOR=#0000ff]New[/COLOR] DEVMODE()
 
                EnumDisplaySettings(device.DeviceName, -[COLOR=#cc66cc]1[/COLOR], otherDeviceMode)
 
                otherDeviceMode.dmPositionX -= offsetx
                otherDeviceMode.dmPositionY -= offsety
 
                ChangeDisplaySettingsEx(device.DeviceName, otherDeviceMode, [COLOR=#cc66cc]0[/COLOR], (CDS_UPDATEREGISTRY [COLOR=#0000ff]Or[/COLOR] CDS_NORESET), [COLOR=#cc66cc]0[/COLOR])
            [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If[/COLOR]
 
            device.cb = Marshal.SizeOf(device)
            otherid += [COLOR=#cc66cc]1[/COLOR]
        [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]While[/COLOR]
 
        [COLOR=#808080]' Apply settings[/COLOR]
        ChangeDisplaySettingsEx([COLOR=#0000ff]Nothing[/COLOR], [COLOR=#cc66cc]0[/COLOR], [COLOR=#cc66cc]0[/COLOR], CDS_NONE, [COLOR=#cc66cc]0[/COLOR])
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]
 
    [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] Button1_Click_1(sender [COLOR=#0000ff]As[/COLOR] System.[COLOR=#0000ff]Object[/COLOR], e [COLOR=#0000ff]As[/COLOR] System.Windows.RoutedEventArgs) [COLOR=#0000ff]Handles[/COLOR] Button1.Click
        SetAsPrimaryMonitor([COLOR=#cc66cc]0[/COLOR])
    [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Class[/COLOR]
 
Last edited:
Top Bottom