Changing the screen resolution in VB.NET

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

        Do
            blnWorked = EnumDisplaySettings(0, i, DevM)
            If blnWorked Then
                If DevM.dmPelsWidth = iWidth And DevM.dmPelsHeight = iHeight Then
                    Debug.WriteLine(DevM.dmBitsPerPel)
                    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
gbiliosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.startposition.aspx

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)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gbiliosAuthor Commented:
you mean like this:

Dim instance As New Form

        Dim value As FormStartPosition

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


OR

 Me.Location = New Point(200, 200)
0
grayeCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.