73

Visual C#を使用して画面解像度を収集および変更するにはどうすればよいですか?

4

7 に答える 7

98

画面の解像度を取得するには、System.Windows.Forms.Screenクラスを使用する必要があります。プロパティを使用して、システム上のすべてのディスプレイのScreen.AllScreensコレクションにアクセスしたり、Screen.PrimaryScreenプロパティを使用してプライマリ ディスプレイにアクセスしたりできます。

クラスにはというScreenプロパティがありBounds、これを使用して、クラスの現在のインスタンスの解像度を決定できます。たとえば、現在の画面の解像度を決定するには、次のようにします。

Rectangle resolution = Screen.PrimaryScreen.Bounds;

解像度を変更するには、もう少し複雑になります。この記事(またはこの記事) は、詳細な実装と説明を提供します。お役に立てれば。

于 2011-02-22T19:10:00.587 に答える
1

in Winforms, there is a Screen class you can use to get data about screen dimensions and color depth for all displays connected to the computer. Here's the docs page: http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

CHANGING the screen resolution is trickier. There is a Resolution third party class that wraps the native code you'd otherwise hook into. Use its CResolution nested class to set the screen resolution to a new height and width; but understand that doing this will only work for height/width combinations the display actually supports (800x600, 1024x768, etc, not 817x435).

于 2011-02-22T19:08:24.507 に答える
0

画面解像度を収集したい場合は、WPF ウィンドウ内で次のコードを実行できます (ウィンドウはthisが参照するものです)。

System.Windows.Media.Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
Double dpiX = m.M11 * 96;
Double dpiY = m.M22 * 96;
于 2011-02-22T19:10:09.370 に答える