Visual C#を使用して画面解像度を収集および変更するにはどうすればよいですか?
7 に答える
画面の解像度を取得するには、System.Windows.Forms.Screen
クラスを使用する必要があります。プロパティを使用して、システム上のすべてのディスプレイのScreen.AllScreens
コレクションにアクセスしたり、Screen.PrimaryScreen
プロパティを使用してプライマリ ディスプレイにアクセスしたりできます。
クラスにはというScreen
プロパティがありBounds
、これを使用して、クラスの現在のインスタンスの解像度を決定できます。たとえば、現在の画面の解像度を決定するには、次のようにします。
Rectangle resolution = Screen.PrimaryScreen.Bounds;
解像度を変更するには、もう少し複雑になります。この記事(またはこの記事) は、詳細な実装と説明を提供します。お役に立てれば。
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).
画面解像度を収集したい場合は、WPF ウィンドウ内で次のコードを実行できます (ウィンドウはthis
が参照するものです)。
System.Windows.Media.Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
Double dpiX = m.M11 * 96;
Double dpiY = m.M22 * 96;