Bildschirmauflösung ändern

  • VB.NET

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von keydrow.

    Bildschirmauflösung ändern

    Hallo Leute,
    ohne groß rumzureden wie kann ich die Bildschirmauflösung ändern? Ich benutze VB12 und finde nur Sachen die für VB6 u. älter gedacht sind.
    Was hast du den eingegeben? Ich habe es mit "vb bildschirmauflösung ändern", "vb 10 bildschirmauflösung ändern" und "vb 12 bildschirmauflösung ändern" probiert.
    Ok danke das mit dem Converter wusste ich schon. Der Converter sagt mir das:

    Resolution.ScreenResolution.ChangeResolution(Width, Height)

    in VB das ist

    VB.NET-Quellcode

    1. Resolution.ScreenResolution.ChangeResolution(Width, Height)

    Nur das Problem VB Zeigt mir das als Fehler an.

    "Resolution" wurde nicht deklariert. Auf das Objekt kann aufgrund seiner Schutzstufe möglicherweise nicht zugegriffen werden.

    Mich macht das "Schutzstufe" Stutzig.
    So ich hab jetzt meine Klasse Resolution
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System
    2. Imports System.Windows.Forms
    3. Imports System.Runtime.InteropServices
    4. Class Resolution
    5. <StructLayout(LayoutKind.Sequential)> _
    6. Public Structure DEVMODE1
    7. <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
    8. Public dmDeviceName As String
    9. Public dmSpecVersion As Short
    10. Public dmDriverVersion As Short
    11. Public dmSize As Short
    12. Public dmDriverExtra As Short
    13. Public dmFields As Integer
    14. Public dmOrientation As Short
    15. Public dmPaperSize As Short
    16. Public dmPaperLength As Short
    17. Public dmPaperWidth As Short
    18. Public dmScale As Short
    19. Public dmCopies As Short
    20. Public dmDefaultSource As Short
    21. Public dmPrintQuality As Short
    22. Public dmColor As Short
    23. Public dmDuplex As Short
    24. Public dmYResolution As Short
    25. Public dmTTOption As Short
    26. Public dmCollate As Short
    27. <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
    28. Public dmFormName As String
    29. Public dmLogPixels As Short
    30. Public dmBitsPerPel As Short
    31. Public dmPelsWidth As Integer
    32. Public dmPelsHeight As Integer
    33. Public dmDisplayFlags As Integer
    34. Public dmDisplayFrequency As Integer
    35. Public dmICMMethod As Integer
    36. Public dmICMIntent As Integer
    37. Public dmMediaType As Integer
    38. Public dmDitherType As Integer
    39. Public dmReserved1 As Integer
    40. Public dmReserved2 As Integer
    41. Public dmPanningWidth As Integer
    42. Public dmPanningHeight As Integer
    43. End Structure
    44. Class User_32
    45. <DllImport("user32.dll")> _
    46. Public Shared Function EnumDisplaySettings(deviceName As String, modeNum As Integer, ByRef devMode As DEVMODE1) As Integer
    47. End Function
    48. <DllImport("user32.dll")> _
    49. Public Shared Function ChangeDisplaySettings(ByRef devMode As DEVMODE1, flags As Integer) As Integer
    50. End Function
    51. Public Const ENUM_CURRENT_SETTINGS As Integer = -1
    52. Public Const CDS_UPDATEREGISTRY As Integer = &H1
    53. Public Const CDS_TEST As Integer = &H2
    54. Public Const DISP_CHANGE_SUCCESSFUL As Integer = 0
    55. Public Const DISP_CHANGE_RESTART As Integer = 1
    56. Public Const DISP_CHANGE_FAILED As Integer = -1
    57. End Class
    58. Namespace Resolution
    59. Public NotInheritable Class ScreenResolution
    60. Private Sub New()
    61. End Sub
    62. ''' <summary>
    63. ''' Ändert die Bildschirmauflösung in die gewünschte Größe
    64. ''' </summary>
    65. ''' <param name="width"></param>
    66. ''' <param name="height"></param>
    67. Public Shared Sub ChangeResolution(width As Integer, height As Integer)
    68. Dim screen__1 As Screen = Screen.PrimaryScreen
    69. Dim iWidth As Integer = width
    70. Dim iHeight As Integer = height
    71. Dim dm As New DEVMODE1()
    72. dm.dmDeviceName = New [String](New Char(31) {})
    73. dm.dmFormName = New [String](New Char(31) {})
    74. dm.dmSize = CShort(Marshal.SizeOf(dm))
    75. If 0 <> User_32.EnumDisplaySettings(Nothing, User_32.ENUM_CURRENT_SETTINGS, dm) Then
    76. dm.dmPelsWidth = iWidth
    77. dm.dmPelsHeight = iHeight
    78. Dim iRet As Integer = User_32.ChangeDisplaySettings(dm, User_32.CDS_TEST)
    79. If iRet = User_32.DISP_CHANGE_FAILED Then
    80. MessageBox.Show("Unable to process your request")
    81. MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    82. Else
    83. iRet = User_32.ChangeDisplaySettings(dm, User_32.CDS_UPDATEREGISTRY)
    84. Select Case iRet
    85. Case User_32.DISP_CHANGE_SUCCESSFUL
    86. If True Then
    87. Exit Select
    88. 'successfull change
    89. End If
    90. Case User_32.DISP_CHANGE_RESTART
    91. If True Then
    92. MessageBox.Show("Description: You Need To Reboot For The Change To Happen." & vbLf & " If You Feel Any Problem After Rebooting Your Machine" & vbLf & "Then Try To Change Resolution In Safe Mode.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    93. Exit Select
    94. 'windows 9x series you have to restart
    95. End If
    96. Case Else
    97. If True Then
    98. MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    99. Exit Select
    100. 'failed to change
    101. End If
    102. End Select
    103. End If
    104. End If
    105. End Sub
    106. End Class
    107. End Namespace
    108. End Class

    Jetzt Kommen die Fehler:
    Namespace-Anweisungen können nur auf Namespace- oder Dateiebene verwendet werden.Zeile:71

    "ScreenResolution" ist kein Member von "Test.Resolution"
    *facepalm* Fehler Selber Gefunden!
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System
    2. Imports System.Windows.Forms
    3. Imports System.Runtime.InteropServices
    4. Class Resolutions
    5. End Class
    6. <StructLayout(LayoutKind.Sequential)> _
    7. Public Structure DEVMODE1
    8. <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
    9. Public dmDeviceName As String
    10. Public dmSpecVersion As Short
    11. Public dmDriverVersion As Short
    12. Public dmSize As Short
    13. Public dmDriverExtra As Short
    14. Public dmFields As Integer
    15. Public dmOrientation As Short
    16. Public dmPaperSize As Short
    17. Public dmPaperLength As Short
    18. Public dmPaperWidth As Short
    19. Public dmScale As Short
    20. Public dmCopies As Short
    21. Public dmDefaultSource As Short
    22. Public dmPrintQuality As Short
    23. Public dmColor As Short
    24. Public dmDuplex As Short
    25. Public dmYResolution As Short
    26. Public dmTTOption As Short
    27. Public dmCollate As Short
    28. <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
    29. Public dmFormName As String
    30. Public dmLogPixels As Short
    31. Public dmBitsPerPel As Short
    32. Public dmPelsWidth As Integer
    33. Public dmPelsHeight As Integer
    34. Public dmDisplayFlags As Integer
    35. Public dmDisplayFrequency As Integer
    36. Public dmICMMethod As Integer
    37. Public dmICMIntent As Integer
    38. Public dmMediaType As Integer
    39. Public dmDitherType As Integer
    40. Public dmReserved1 As Integer
    41. Public dmReserved2 As Integer
    42. Public dmPanningWidth As Integer
    43. Public dmPanningHeight As Integer
    44. End Structure
    45. Class User_32
    46. <DllImport("user32.dll")> _
    47. Public Shared Function EnumDisplaySettings(deviceName As String, modeNum As Integer, ByRef devMode As DEVMODE1) As Integer
    48. End Function
    49. <DllImport("user32.dll")> _
    50. Public Shared Function ChangeDisplaySettings(ByRef devMode As DEVMODE1, flags As Integer) As Integer
    51. End Function
    52. Public Const ENUM_CURRENT_SETTINGS As Integer = -1
    53. Public Const CDS_UPDATEREGISTRY As Integer = &H1
    54. Public Const CDS_TEST As Integer = &H2
    55. Public Const DISP_CHANGE_SUCCESSFUL As Integer = 0
    56. Public Const DISP_CHANGE_RESTART As Integer = 1
    57. Public Const DISP_CHANGE_FAILED As Integer = -1
    58. End Class
    59. Namespace Resolution
    60. Public NotInheritable Class ScreenResolution
    61. Private Sub New()
    62. End Sub
    63. ''' <summary>
    64. ''' Ändert die Bildschirmauflösung in die gewünschte Größe
    65. ''' </summary>
    66. ''' <param name="width"></param>
    67. ''' <param name="height"></param>
    68. Public Shared Sub ChangeResolution(width As Integer, height As Integer)
    69. Dim screen__1 As Screen = Screen.PrimaryScreen
    70. Dim iWidth As Integer = width
    71. Dim iHeight As Integer = height
    72. Dim dm As New DEVMODE1()
    73. dm.dmDeviceName = New [String](New Char(31) {})
    74. dm.dmFormName = New [String](New Char(31) {})
    75. dm.dmSize = CShort(Marshal.SizeOf(dm))
    76. If 0 <> User_32.EnumDisplaySettings(Nothing, User_32.ENUM_CURRENT_SETTINGS, dm) Then
    77. dm.dmPelsWidth = iWidth
    78. dm.dmPelsHeight = iHeight
    79. Dim iRet As Integer = User_32.ChangeDisplaySettings(dm, User_32.CDS_TEST)
    80. If iRet = User_32.DISP_CHANGE_FAILED Then
    81. MessageBox.Show("Unable to process your request")
    82. MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    83. Else
    84. iRet = User_32.ChangeDisplaySettings(dm, User_32.CDS_UPDATEREGISTRY)
    85. Select Case iRet
    86. Case User_32.DISP_CHANGE_SUCCESSFUL
    87. If True Then
    88. Exit Select
    89. 'successfull change
    90. End If
    91. Case User_32.DISP_CHANGE_RESTART
    92. If True Then
    93. MessageBox.Show("Description: You Need To Reboot For The Change To Happen." & vbLf & " If You Feel Any Problem After Rebooting Your Machine" & vbLf & "Then Try To Change Resolution In Safe Mode.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    94. Exit Select
    95. 'windows 9x series you have to restart
    96. End If
    97. Case Else
    98. If True Then
    99. MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    100. Exit Select
    101. 'failed to change
    102. End If
    103. End Select
    104. End If
    105. End If
    106. End Sub
    107. End Class
    108. End Namespace