Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created September 7, 2012 04:09
Show Gist options
  • Save pinzolo/3663046 to your computer and use it in GitHub Desktop.
Save pinzolo/3663046 to your computer and use it in GitHub Desktop.
[WPF]ウィンドウをデスクトップの任意の位置に表示させる
// System.Windows.Forms と System.Drawing を参照設定に追加する必要がある。
// この例では通知ウィンドウを右下に表示させるというシナリオ
/// <summary>
/// 通知ウィンドウ表示時の画面からのマージン
/// </summary>
private const int NOTIFICATION_WINDOW_DISPLAY_MARGIN = 5;
/// <summary>
/// 指定のメッセージをユーザーに知らせるダイアログを表示する。
/// </summary>
/// <param name="message">通知メッセージ</param>
private void Notify(string message)
{
var notificationWindow = new NotificationWindow();
var desktop = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
notificationWindow.Top = desktop.Height - (notificationWindow.Height + NOTIFICATION_WINDOW_DISPLAY_MARGIN);
notificationWindow.Left = desktop.Width - (notificationWindow.Width + NOTIFICATION_WINDOW_DISPLAY_MARGIN);
notificationWindow.Owner = this;
notificationWindow.Show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment