/// <summary> /// Constructors /// </summary> public RadWindowAlertManager(Window owner, AlertScreenPosition alertScreenPosition = AlertScreenPosition.BottomRight) { _owner = owner ?? throw new ArgumentNullException(nameof(owner)); _alertScreenPosition = alertScreenPosition; if ((HwndSource)HwndSource.FromVisual(_owner) != null) { recreateManager(); } else { _owner.Loaded += ownerLoaded; } _owner.LocationChanged += ownerLocationChanged; _owner.SizeChanged += ownerSizeChanged; }
/// <summary> /// GetAlertOffsetPosition. /// </summary> Point getAlertOffsetPosition(AlertScreenPosition alertScreenPos) { HwndSource source = (HwndSource)HwndSource.FromVisual(_owner); if (source != null) { if (Win32.GetClientRect(source.Handle, out Win32.RECT cr) && Win32.GetWindowRect(source.Handle, out Win32.RECT wr)) { var windowRect = new Rect(wr.Left, wr.Top, wr.Right - wr.Left, wr.Bottom - wr.Top); var clientRect = new Rect(cr.Left, cr.Top, cr.Right - cr.Left, cr.Bottom - cr.Top); var clientPos = new System.Drawing.Point((int)clientRect.Left, (int)clientRect.Top); Win32.ClientToScreen(source.Handle, ref clientPos); var barSize = (Int32)(clientPos.X - windowRect.X); clientRect.Offset(clientPos.X, clientPos.Y); switch (alertScreenPos) { case AlertScreenPosition.TopLeft: return(new Point(clientPos.X + barSize - SystemParameters.WorkArea.X, clientPos.Y + barSize - SystemParameters.WorkArea.Y)); case AlertScreenPosition.TopCenter: return(new Point(clientPos.X + barSize + (clientRect.Width * 0.5) - (SystemParameters.WorkArea.Width * 0.5), clientPos.Y + barSize - SystemParameters.WorkArea.Y)); case AlertScreenPosition.TopRight: return(new Point(windowRect.Right - (barSize * 2) - SystemParameters.WorkArea.Right, clientPos.Y + barSize - SystemParameters.WorkArea.Y)); case AlertScreenPosition.BottomLeft: return(new Point(clientPos.X + barSize - SystemParameters.WorkArea.X, windowRect.BottomLeft.Y - barSize - SystemParameters.WorkArea.Bottom)); case AlertScreenPosition.BottomCenter: return(new Point(clientPos.X + barSize + (clientRect.Width * 0.5) - (SystemParameters.WorkArea.Width * 0.5), windowRect.BottomLeft.Y - barSize - SystemParameters.WorkArea.Bottom)); case AlertScreenPosition.BottomRight: return(new Point(windowRect.Right - (barSize * 2) - SystemParameters.WorkArea.Right, windowRect.BottomLeft.Y - barSize - SystemParameters.WorkArea.Bottom)); } } } return(new Point(0, 0)); }
/// <summary> /// 右下角顯示警告提示 /// </summary> /// <param name="Title">標題</param> /// <param name="Content">內容</param> /// <param name="CloseDelayTime">自動消失秒數(預設6秒)</param> /// <param name="ScreenDisplayPosition">提示顯示位置(Enum AlertScreenPosition)</param> /// <param name="PopupLocation">提示位置手動設定(new Point())</param> private void ShowDesktopAlert(string Title, string Content, int CloseDelayTime = 6, AlertScreenPosition ScreenDisplayPosition = AlertScreenPosition.BottomRight, Point PopupLocation = new Point()) { try { Font LabelFont = new Font("微軟正黑體", 12f, FontStyle.Regular); Font DesktopAlertTextBtnFont = new Font("微軟正黑體", 16f, FontStyle.Bold); RadDesktopAlert radDesktopAlert = new RadDesktopAlert(); radDesktopAlert.ScreenPosition = ScreenDisplayPosition; if (ScreenDisplayPosition == AlertScreenPosition.Manual) { DesktopAlertPopup alertpopup = radDesktopAlert.Popup as DesktopAlertPopup; if (alertpopup != null) { alertpopup.Location = PopupLocation; } } radDesktopAlert.AutoClose = true; radDesktopAlert.AutoCloseDelay = CloseDelayTime; radDesktopAlert.CaptionText = Title; radDesktopAlert.ContentText = Content; //radDesktopAlert.ThemeName = "FluentDatk"; radDesktopAlert.AutoSize = true; //radDesktopAlert.ScreenPosition = AlertScreenPosition.BottomRight; radDesktopAlert.ShowCloseButton = true; radDesktopAlert.ShowOptionsButton = false; radDesktopAlert.ShowPinButton = false; radDesktopAlert.Popup.AlertElement.ContentElement.Font = LabelFont; radDesktopAlert.Popup.AlertElement.CaptionElement.TextAndButtonsElement.Font = DesktopAlertTextBtnFont; radDesktopAlert.Show(); } catch { throw; } }