private void Init() { _screens = WpfScreen.AllScreens(); //arrange displays by X _screens.Sort((s1, s2) => (int)(s1.DeviceBounds.Left - s2.DeviceBounds.Left)); foreach (var scr in _screens) { Debug.WriteLine(scr); } _borders = new BorderBetweenDisplays[_screens.Count - 1]; var bounds = WPF_Helper.VirtualScreenBounds(); for (int i = 1; i < _screens.Count; i++) { _borders[i - 1] = new BorderBetweenDisplays() { Index = i - 1, DisplayToDisplay_X = _screens[i - 1].DeviceBounds.Right, FromDisplayToDisplay_Top = Math.Max(_screens[i].DeviceBounds.Top, _screens[i - 1].DeviceBounds.Top), FromDisplayToDisplay_Bottom = Math.Min(_screens[i].DeviceBounds.Bottom, _screens[i - 1].DeviceBounds.Bottom) }; } }
//if timeout is set and window is not closed after timeout - click default button internal Thread CloseWindowOnTimeout(int timeout) { if (timeout < 100) { return(null); } Thread t = new Thread(() => { if (timeout < 2000) { Thread.Sleep(timeout); } else { int count = timeout / 300; for (int i = 0; i < count; i++) { Thread.Sleep(300); int idx = i; WPF_Helper.ExecuteOnUIThread(() => { UpdateDefaultButtonTimeout(idx * 300, timeout); return(0); }); } } if (IsVisible) { WPF_Helper.ExecuteOnUIThread(() => { DefaultCommand.Execute(this); return(0); }); } }); t.Name = "AutoCloseMessage"; t.Start(); return(t); }
private static void CenterToRectangle(this Window window, Rect rOwner) { Point location = WPF_Helper.CenterToRectangle(new Size(window.Width, window.Height), rOwner); window.Left = location.X; window.Top = location.Y; }
public static void Init() { MainForm = WPF_Helper.TopmostForm(); if (Application.Current != null) { CurrentDispatcher = Application.Current.Dispatcher; } }
private static Window GetWindowImpl(UIElement owner) { if (owner == null) { return(WPF_Helper.GetMainWindow()); } return(Window.GetWindow(owner)); }
public static PopUp.PopUpResult MessageBox(this UIElement owner, string message, string title, MessageBoxImage icon = MessageBoxImage.Information, TextAlignment textAlignment = TextAlignment.Center, PopUp.PopUpButtonsType buttonsType = PopUp.PopUpButtonsType.OK, int timeout = Timeout.Infinite) { PopUp.PopUpButtons buttons = new PopUp.PopUpButtons(buttonsType); return(WPF_Helper.ExecuteOnUIThreadWPF(() => { return MessageWindowExtension.MessageBox(owner, ref message, title, icon, textAlignment, buttons, timeout); })); }
public static PopUp.PopUpResult MessageBoxEx(this System.Windows.Forms.Control owner, string message, string title, MessageBoxImage icon = MessageBoxImage.Information, TextAlignment textAlignment = TextAlignment.Center, PopUp.PopUpButtons buttons = null, int timeout = Timeout.Infinite) { if (buttons == null) { buttons = new PopUp.PopUpButtons(PopUp.PopUpButtonsType.OK); } return(WPF_Helper.ExecuteOnUIThreadForm(() => { return MessageWindowExtension.MessageBox(owner.Handle, ref message, title, icon, textAlignment, buttons, timeout); })); }
public MessageWindow(PopUp.PopUpButtons buttons) { _buttons = buttons; //_defaultButton = defaultButton; InitializeComponent(); DataContext = this; DefaultCommand = new RelayCommand((o) => { if (btn1.IsDefault) { btn1_Click(o, new RoutedEventArgs()); } else if (btn2.IsDefault) { btn2_Click(o, new RoutedEventArgs()); } else if (btn3.IsDefault) { btn3_Click(o, new RoutedEventArgs()); } }); EscapeCommand = new RelayCommand((o) => { CloseBtn_OnClick(o, new RoutedEventArgs()); }); //Foot pedal (F6) F6Command = new RelayCommand((o) => { btn3_Click(o, new RoutedEventArgs()); }); //Foot pedal (F5) F5Command = new RelayCommand((o) => { btn2_Click(o, new RoutedEventArgs()); }); //Foot pedal (F5) CopyCommand = new RelayCommand((o) => { Copy_Click(o, new RoutedEventArgs()); }); imgCopy.Source = WPF_Helper.GetResourceImage("WPF\\WPFMessageBox\\Images\\COPY.PNG"); }
public static PopUpResult InputBox(ref string userInput, string title, MessageBoxImage icon = MessageBoxImage.Information, TextAlignment textAlignment = TextAlignment.Justify, PopUpButtonsType buttonsType = PopUpButtonsType.CancelOK, int timeout = Timeout.Infinite) { PopUpButtons buttons = new PopUpButtons(buttonsType); string message = userInput; PopUpResult res = WPF_Helper.ExecuteOnUIThread(() => { return(MessageWindowExtension.MessageBox(null, ref message, title, icon, textAlignment, buttons, timeout, false)); }); userInput = message; return(res); }
private void CreateDisplaysRectangles() { var displays = WpfScreen.AllScreens(); displays.Sort((d1, d2) => (int)(d1.DeviceBounds.Left - d2.DeviceBounds.Left)); _diplayRectangles.ForEach(disp => disp.Draggable(false)); _diplayRectangles.Clear(); var desktopBounds = WPF_Helper.VirtualScreenBounds(); displays.ForEach((disp) => { Border r = new Border(); r.Opacity = 0.85; r.BorderBrush = Brushes.DimGray; r.Background = Brushes.AliceBlue; r.BorderThickness = new Thickness(3); r.CornerRadius = new CornerRadius(3); r.Width = disp.DeviceBounds.Width / 10.0; r.Height = disp.DeviceBounds.Height / 10.0; Canvas.SetLeft(r, (disp.DeviceBounds.Left - desktopBounds.Left) / 10.0); Canvas.SetTop(r, (disp.DeviceBounds.Top - desktopBounds.Top) / 10.0); r.Draggable(); r.LayoutUpdated += (s, e) => { Debug.WriteLine("R - moved"); }; TextBlock txt = new TextBlock(); txt.FontSize = 16; txt.TextAlignment = TextAlignment.Center; txt.Text = string.Format("Display [{0}]\n\n{1}", disp.Index, disp.WorkingArea); r.Child = txt; _diplayRectangles.Add(r); }); }
/// <summary> /// Show Message Box, using main app window(WinForms or WPF) as owner, /// If btn*text is null will assign text by 'buttons' /// </summary> /// <param name="GetOwnerOnUIThread">function that returns WPF UIElement to center on, wull be executed on UI thread, can be null</param> /// <param name="message"></param> /// <param name="title"></param> /// <param name="icon"></param> /// <param name="textAlignment"></param> /// <param name="buttons"></param> /// <param name="timeout">execute default action after timeout if more than 100 milliseconds</param> /// <returns></returns> public static PopUpResult MessageBox(Func <UIElement> GetOwnerOnUIThread, string message, string title, MessageBoxImage icon, TextAlignment textAlignment = TextAlignment.Center, PopUpButtons buttons = null, int timeout = Timeout.Infinite) { if (buttons == null) { buttons = new PopUpButtons(PopUpButtonsType.OK); } return(WPF_Helper.ExecuteOnUIThread(() => { UIElement owner = null; if (GetOwnerOnUIThread != null) { owner = GetOwnerOnUIThread(); } return MessageWindowExtension.MessageBox(owner, ref message, title, icon, textAlignment, buttons, timeout, true); })); }
/// <summary> /// Calculate size of message and adjust window size correspondently /// </summary> internal Point AdjustSize(string newText, bool growAndShrink) { WPF_Helper.UpdateScaleWPF(txtMessage); var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(this).Handle); double deltaWidth = 70; double deltaHeight = 140; double deltaWidthTitle = 80; //restrict size to 80% of display double maxWidth = screen.Bounds.Width * 0.8 - deltaWidth; double maxHeight = screen.Bounds.Height * 0.9 - deltaHeight; //minimal height for input box (not readonly) double minHeight = txtMessage.IsReadOnly ? this.MinHeight + 50 : this.MinHeight; //calculate message size Size size = MeasureString(newText, txtMessage); //calculate buttons size Size buttonsSize = CalculateButtonsSize(); if (buttonsSize.Width > size.Width) { size.Width = buttonsSize.Width; } //calculate title size Size sizeTitle = MeasureString(txtTitle); if (sizeTitle.Width + deltaWidthTitle > maxWidth) { txtTitle.ToolTip = txtTitle.Text; //if title will be cut - add tooltip } //if title is wider than message if (sizeTitle.Width < maxWidth - deltaWidthTitle && sizeTitle.Width + deltaWidthTitle > size.Width) { size.Width = sizeTitle.Width + deltaWidthTitle; } if (size.Width > maxWidth) { size.Width = maxWidth; } if (size.Width < this.MinWidth - deltaWidth) { size.Width = this.MinWidth - deltaWidth; } if (size.Height > maxHeight) { size.Height = maxHeight; } if (size.Height < minHeight - deltaHeight) { size.Height = minHeight - deltaHeight; } double deltaX = Math.Round(size.Width + deltaWidth - this.ActualWidth); double deltaY = Math.Round(size.Height + deltaHeight - this.ActualHeight); //grow only if (growAndShrink || size.Width + deltaWidth > this.Width) { this.Width = size.Width + deltaWidth; this.Left -= deltaX / 2; } if (growAndShrink || size.Height + deltaHeight > this.Height) { this.Height = size.Height + deltaHeight; } //for very long lines - scroll to the middle if (sTextAlignment == TextAlignment.Center) { txtMessage.ScrollToHorizontalOffset(size.Width / 2); } return(new Point(deltaX, deltaY)); }
public static BitmapImage GetFromResource(string path) { return(WPF_Helper.GetResourceImage(path)); }
private static void CenterToMainWindow(this Window window) { Rect r = WPF_Helper.GetMainWindowRect(); window.CenterToRectangle(r); }