Bildschirmauflösung ändern
- VB.NET
Sie verwenden einen veralteten Browser (%browser%) mit Sicherheitsschwachstellen und können nicht alle Funktionen dieser Webseite nutzen.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von keydrow.
-
-
Lern doch bitte mal zu Googlen.
Die ersten 3 Treffer sind genau richtig.
mycsharp.de/wbb2/thread.php?threadid=39727 -
-
-
@keydrow: Such am besten immer mit ".net" hintendran.
Es gibt viele Beispiele im Netz welche aber oft mehr in C# als wie in VB verfasst sind.
C# Code kannst du du im Normalfall per Online Converter auf VB-Code konvertieren lassen.
lgScheduleLib 0.0.1.0
Kleine Lib zum Anlaufen von Code zu bestimmten Zeiten -
Ok danke das mit dem Converter wusste ich schon. Der Converter sagt mir das:
Resolution.ScreenResolution.ChangeResolution(Width, Height)
in VB das ist
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
- Imports System
- Imports System.Windows.Forms
- Imports System.Runtime.InteropServices
- Class Resolution
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure DEVMODE1
- <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
- Public dmDeviceName As String
- Public dmSpecVersion As Short
- Public dmDriverVersion As Short
- Public dmSize As Short
- Public dmDriverExtra As Short
- Public dmFields As Integer
- Public dmOrientation As Short
- Public dmPaperSize As Short
- Public dmPaperLength As Short
- Public dmPaperWidth As Short
- Public dmScale As Short
- Public dmCopies As Short
- Public dmDefaultSource As Short
- Public dmPrintQuality As Short
- Public dmColor As Short
- Public dmDuplex As Short
- Public dmYResolution As Short
- Public dmTTOption As Short
- Public dmCollate As Short
- <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
- Public dmFormName As String
- Public dmLogPixels As Short
- Public dmBitsPerPel As Short
- Public dmPelsWidth As Integer
- Public dmPelsHeight As Integer
- Public dmDisplayFlags As Integer
- Public dmDisplayFrequency As Integer
- Public dmICMMethod As Integer
- Public dmICMIntent As Integer
- Public dmMediaType As Integer
- Public dmDitherType As Integer
- Public dmReserved1 As Integer
- Public dmReserved2 As Integer
- Public dmPanningWidth As Integer
- Public dmPanningHeight As Integer
- End Structure
- Class User_32
- <DllImport("user32.dll")> _
- Public Shared Function EnumDisplaySettings(deviceName As String, modeNum As Integer, ByRef devMode As DEVMODE1) As Integer
- End Function
- <DllImport("user32.dll")> _
- Public Shared Function ChangeDisplaySettings(ByRef devMode As DEVMODE1, flags As Integer) As Integer
- End Function
- Public Const ENUM_CURRENT_SETTINGS As Integer = -1
- Public Const CDS_UPDATEREGISTRY As Integer = &H1
- Public Const CDS_TEST As Integer = &H2
- Public Const DISP_CHANGE_SUCCESSFUL As Integer = 0
- Public Const DISP_CHANGE_RESTART As Integer = 1
- Public Const DISP_CHANGE_FAILED As Integer = -1
- End Class
- Namespace Resolution
- Public NotInheritable Class ScreenResolution
- Private Sub New()
- End Sub
- ''' <summary>
- ''' Ändert die Bildschirmauflösung in die gewünschte Größe
- ''' </summary>
- ''' <param name="width"></param>
- ''' <param name="height"></param>
- Public Shared Sub ChangeResolution(width As Integer, height As Integer)
- Dim screen__1 As Screen = Screen.PrimaryScreen
- Dim iWidth As Integer = width
- Dim iHeight As Integer = height
- Dim dm As New DEVMODE1()
- dm.dmDeviceName = New [String](New Char(31) {})
- dm.dmFormName = New [String](New Char(31) {})
- dm.dmSize = CShort(Marshal.SizeOf(dm))
- If 0 <> User_32.EnumDisplaySettings(Nothing, User_32.ENUM_CURRENT_SETTINGS, dm) Then
- dm.dmPelsWidth = iWidth
- dm.dmPelsHeight = iHeight
- Dim iRet As Integer = User_32.ChangeDisplaySettings(dm, User_32.CDS_TEST)
- If iRet = User_32.DISP_CHANGE_FAILED Then
- MessageBox.Show("Unable to process your request")
- MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Else
- iRet = User_32.ChangeDisplaySettings(dm, User_32.CDS_UPDATEREGISTRY)
- Select Case iRet
- Case User_32.DISP_CHANGE_SUCCESSFUL
- If True Then
- Exit Select
- 'successfull change
- End If
- Case User_32.DISP_CHANGE_RESTART
- If True Then
- 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)
- Exit Select
- 'windows 9x series you have to restart
- End If
- Case Else
- If True Then
- MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Exit Select
- 'failed to change
- End If
- End Select
- End If
- End If
- End Sub
- End Class
- End Namespace
- 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
- Imports System
- Imports System.Windows.Forms
- Imports System.Runtime.InteropServices
- Class Resolutions
- End Class
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure DEVMODE1
- <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
- Public dmDeviceName As String
- Public dmSpecVersion As Short
- Public dmDriverVersion As Short
- Public dmSize As Short
- Public dmDriverExtra As Short
- Public dmFields As Integer
- Public dmOrientation As Short
- Public dmPaperSize As Short
- Public dmPaperLength As Short
- Public dmPaperWidth As Short
- Public dmScale As Short
- Public dmCopies As Short
- Public dmDefaultSource As Short
- Public dmPrintQuality As Short
- Public dmColor As Short
- Public dmDuplex As Short
- Public dmYResolution As Short
- Public dmTTOption As Short
- Public dmCollate As Short
- <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
- Public dmFormName As String
- Public dmLogPixels As Short
- Public dmBitsPerPel As Short
- Public dmPelsWidth As Integer
- Public dmPelsHeight As Integer
- Public dmDisplayFlags As Integer
- Public dmDisplayFrequency As Integer
- Public dmICMMethod As Integer
- Public dmICMIntent As Integer
- Public dmMediaType As Integer
- Public dmDitherType As Integer
- Public dmReserved1 As Integer
- Public dmReserved2 As Integer
- Public dmPanningWidth As Integer
- Public dmPanningHeight As Integer
- End Structure
- Class User_32
- <DllImport("user32.dll")> _
- Public Shared Function EnumDisplaySettings(deviceName As String, modeNum As Integer, ByRef devMode As DEVMODE1) As Integer
- End Function
- <DllImport("user32.dll")> _
- Public Shared Function ChangeDisplaySettings(ByRef devMode As DEVMODE1, flags As Integer) As Integer
- End Function
- Public Const ENUM_CURRENT_SETTINGS As Integer = -1
- Public Const CDS_UPDATEREGISTRY As Integer = &H1
- Public Const CDS_TEST As Integer = &H2
- Public Const DISP_CHANGE_SUCCESSFUL As Integer = 0
- Public Const DISP_CHANGE_RESTART As Integer = 1
- Public Const DISP_CHANGE_FAILED As Integer = -1
- End Class
- Namespace Resolution
- Public NotInheritable Class ScreenResolution
- Private Sub New()
- End Sub
- ''' <summary>
- ''' Ändert die Bildschirmauflösung in die gewünschte Größe
- ''' </summary>
- ''' <param name="width"></param>
- ''' <param name="height"></param>
- Public Shared Sub ChangeResolution(width As Integer, height As Integer)
- Dim screen__1 As Screen = Screen.PrimaryScreen
- Dim iWidth As Integer = width
- Dim iHeight As Integer = height
- Dim dm As New DEVMODE1()
- dm.dmDeviceName = New [String](New Char(31) {})
- dm.dmFormName = New [String](New Char(31) {})
- dm.dmSize = CShort(Marshal.SizeOf(dm))
- If 0 <> User_32.EnumDisplaySettings(Nothing, User_32.ENUM_CURRENT_SETTINGS, dm) Then
- dm.dmPelsWidth = iWidth
- dm.dmPelsHeight = iHeight
- Dim iRet As Integer = User_32.ChangeDisplaySettings(dm, User_32.CDS_TEST)
- If iRet = User_32.DISP_CHANGE_FAILED Then
- MessageBox.Show("Unable to process your request")
- MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Else
- iRet = User_32.ChangeDisplaySettings(dm, User_32.CDS_UPDATEREGISTRY)
- Select Case iRet
- Case User_32.DISP_CHANGE_SUCCESSFUL
- If True Then
- Exit Select
- 'successfull change
- End If
- Case User_32.DISP_CHANGE_RESTART
- If True Then
- 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)
- Exit Select
- 'windows 9x series you have to restart
- End If
- Case Else
- If True Then
- MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Exit Select
- 'failed to change
- End If
- End Select
- End If
- End If
- End Sub
- End Class
- End Namespace
-
-