We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Changing the screen resolution in VB.NET

gbilios asked
Medium Priority
Last Modified: 2008-02-01
There was a post asked by MOsosky on 07/23/2004 01:08AM EST about wanting to know how to change the screen resolution in VB.NET.  I copied and pasted the code from the orginal comment here.  

ChangeRes(1024, 768, 32) 'i added this line in the form load and i changed the resolution accordingly - it worked.  I tested the code on other machines and the form starts in different parts of the screen. I want to know how to make sure the form starts in the  same part of the screen.

Imports System.Runtime.InteropServices

    Private Const CCDEVICENAME = 32
    Private Const CCFORMNAME = 32
    Private Const DM_PELSWIDTH = &H80000
    Private Const DM_PELSHEIGHT = &H100000

       <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=4)> _
    Private Structure DEVMODE
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=CCDEVICENAME)> Dim dmDeviceName As String
        Dim dmSpecVersion As Short
        Dim dmDriverVersion As Short
        Dim dmSize As Short
        Dim dmDriverExtra As Short
        Dim dmFields As Integer
        Dim dmOrientation As Short
        Dim dmPaperSize As Short
        Dim dmPaperLength As Short
        Dim dmPaperWidth As Short
        Dim dmScale As Short
        Dim dmCopies As Short
        Dim dmDefaultSource As Short
        Dim dmPrintQuality As Short
        Dim dmColor As Short
        Dim dmDuplex As Short
        Dim dmYResolution As Short
        Dim dmTTOption As Short
        Dim dmCollate As Short
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=CCFORMNAME)> Dim dmFormName As String
        Dim dmUnusedPadding As Short
        Dim dmBitsPerPel As Short
        Dim dmPelsWidth As Integer
        Dim dmPelsHeight As Integer
        Dim dmDisplayFlags As Integer
        Dim dmDisplayFrequency As Integer
    End Structure

    Private Declare Ansi Function EnumDisplaySettings Lib "user32" _
        Alias "EnumDisplaySettingsA" _
        (ByVal lpszDeviceName As Integer, _
        ByVal iModeNum As Integer, _
        ByRef lpDevMode As DEVMODE) As Boolean

    Private Declare Ansi Function ChangeDisplaySettings Lib "user32" _
        Alias "ChangeDisplaySettingsA" _
        (ByRef lpDevMode As DEVMODE, _
        ByVal dwflags As Integer) As Integer

    Private Sub ChangeRes(ByVal iWidth As Integer, ByVal iHeight As Integer, Optional ByVal iColorDepth As Integer = 0)
        Dim blnWorked As Boolean
        Dim i As Integer
        Dim DevM As DEVMODE

        i = 0

            blnWorked = EnumDisplaySettings(0, i, DevM)
            If blnWorked Then
                If DevM.dmPelsWidth = iWidth And DevM.dmPelsHeight = iHeight Then
                    If iColorDepth > 0 Then
                        DevM.dmBitsPerPel = iColorDepth
                    End If
                    ChangeDisplaySettings(DevM, 0)
                    Exit Sub
                End If
            End If
            i = i + 1
        Loop Until (blnWorked = False)

    End Sub
Watch Question

The starting position of the form is controlled by the "StartPostion" property...


If you change the property to "Manual", and se the Location property to 10, 10 then it will always appear in the same spot (10 pixels down, and 10 pixels from the left)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


you mean like this:

Dim instance As New Form

        Dim value As FormStartPosition

        value = instance.StartPosition.CenterParent
        instance.StartPosition = value


 Me.Location = New Point(200, 200)

Either will do it...   Most folks adjust the properties of the form form the GUI (the lower right-hand corner of the IDE), rather than with code
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.