差分
ナビゲーションに移動
検索に移動
[[Xamarin.Mac]]で[[ディスプレイ]]周りの設定がなにかしら変更された際にそれを検出できると色々嬉しい。
==概要==
[[Xamarin.Mac]]で[[ディスプレイ]]周りの設定がなにかしら変更された際にそれを検出できると色々嬉しい。
そんなことより世の中にはなんと外部ディスプレイを接続されるだけでクラッシュするクソアプリがあるらしい。[[デバッグ]]はちゃんとしよう。
==実装1==
AppDelegateのScreenParametersChangedメソッドをオーバーライドするだけで検出できる。
<source lang="csharp">
public partial class AppDelegate : NSApplicationDelegate
{
MainWindowController mainWindowController;
public AppDelegate()
{
}
public override void DidFinishLaunching(NSNotification notification)
{
mainWindowController = new MainWindowController();
mainWindowController.Window.MakeKeyAndOrderFront(this);
ScreenInfo();
}
public override void ScreenParametersChanged(NSNotification notification)
{
ScreenInfo();
}
void ScreenInfo()
{
foreach (var screen in NSScreen.Screens)
{
Console.WriteLine(screen.Frame);
Console.WriteLine(screen.BackingScaleFactor);
Console.WriteLine(screen.Frame.Width * screen.BackingScaleFactor + "," + screen.Frame.Height * screen.BackingScaleFactor);
Console.WriteLine(screen.DeviceDescription);
Console.WriteLine("----");
}
}
}
</source>
==関連項目==
*[[Xamarin.Mac/Retina Displayか判別する]]
==参考文献==
{{reflist}}
{{stub}}
[[category:Xamarin.Mac]]
==概要==
[[Xamarin.Mac]]で[[ディスプレイ]]周りの設定がなにかしら変更された際にそれを検出できると色々嬉しい。
そんなことより世の中にはなんと外部ディスプレイを接続されるだけでクラッシュするクソアプリがあるらしい。[[デバッグ]]はちゃんとしよう。
==実装1==
AppDelegateのScreenParametersChangedメソッドをオーバーライドするだけで検出できる。
<source lang="csharp">
public partial class AppDelegate : NSApplicationDelegate
{
MainWindowController mainWindowController;
public AppDelegate()
{
}
public override void DidFinishLaunching(NSNotification notification)
{
mainWindowController = new MainWindowController();
mainWindowController.Window.MakeKeyAndOrderFront(this);
ScreenInfo();
}
public override void ScreenParametersChanged(NSNotification notification)
{
ScreenInfo();
}
void ScreenInfo()
{
foreach (var screen in NSScreen.Screens)
{
Console.WriteLine(screen.Frame);
Console.WriteLine(screen.BackingScaleFactor);
Console.WriteLine(screen.Frame.Width * screen.BackingScaleFactor + "," + screen.Frame.Height * screen.BackingScaleFactor);
Console.WriteLine(screen.DeviceDescription);
Console.WriteLine("----");
}
}
}
</source>
==関連項目==
*[[Xamarin.Mac/Retina Displayか判別する]]
==参考文献==
{{reflist}}
{{stub}}
[[category:Xamarin.Mac]]