private bool CollectParams() { HudColorsByValueParams.ColorsByValue = new List <ColorByValue>(); var ucColorByValues = StackPanel_ColorsByValue.Children.OfType <UCColorByValue>().ToArray(); if (ucColorByValues.Length > 3) { WindowMessage.ShowDialog(string.Format("Maximum of 3 color ranges are allowed."), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return(false); } foreach (var item in ucColorByValues) { var colorByValue = item.GetColorByValue(); if (colorByValue == null) { WindowMessage.ShowDialog(string.Format("Invalid one or more 'Color By Value' input."), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return(false); } HudColorsByValueParams.ColorsByValue.Add(colorByValue); } return(true); }
public static void DisplayException(Exception e, Window owner, WindowStartupLocation windowStartupLocation) { UiInvoke(() => { string fileName = "pshandler_error_" + DateTime.Now.Ticks + ".log"; StringBuilder sbFile = new StringBuilder(); sbFile.AppendLine("Message: " + e.Message); sbFile.AppendLine("Type: " + e.GetType()); sbFile.AppendLine("Data: " + e.Data); sbFile.AppendLine("HResult: " + e.HResult); sbFile.AppendLine("HelpLink: " + e.HelpLink); sbFile.AppendLine("InnerException: " + e.InnerException); sbFile.AppendLine("Source: " + e.Source); sbFile.AppendLine("TargetSite: " + e.TargetSite); sbFile.AppendLine("StackTrace:"); sbFile.AppendLine(); sbFile.AppendLine(e.StackTrace); File.WriteAllText(fileName, sbFile.ToString()); StringBuilder sbMessageBox = new StringBuilder(); sbMessageBox.AppendLine(e.Message); sbMessageBox.AppendLine(); sbMessageBox.AppendLine(e.GetType().ToString()); sbMessageBox.AppendLine(); sbMessageBox.AppendLine("Log file: " + fileName); WindowMessage.ShowDialog(sbMessageBox.ToString(), "Error", WindowMessageButtons.OK, WindowMessageImage.Error, owner, windowStartupLocation); }); }
private void Button_OK_Click(object sender, RoutedEventArgs e) { if (TextBox_Name.Text.Length == 0) { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", Label_Name.Content), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } if (App.PokerTypeManager.GetPokerTypesCopy().Any(o => o.Name.ToLowerInvariant().Equals(TextBox_Name.Text.ToLowerInvariant()))) { WindowMessage.ShowDialog("Cannot save. Duplicate names.", "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } try { PokerType.LevelLength = TimeSpan.Parse(TextBox_LevelLength.Text); } catch { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", Label_LevelLength.Content), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } try { new Regex(TextBox_RegexWindowTitle.Text); } catch { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", Label_RegexWindowTitle.Content), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } try { new Regex(TextBox_RegexWindowClass.Text); } catch { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", Label_RegexWindowClass.Content), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } PokerType.Name = TextBox_Name.Text; //PokerType.LevelLength = TimeSpan.Parse(TextBox_LevelLength.Text); PokerType.RegexWindowTitle = new Regex(TextBox_RegexWindowTitle.Text); PokerType.RegexWindowClass = new Regex(TextBox_RegexWindowClass.Text); Saved = true; Close(); }
public static void Main() { System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-US"); System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new System.Globalization.CultureInfo("en-US"); try { FileInfo fi = new FileInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); if (!fi.Name.Equals("PsHandler.exe") && !fi.Name.Equals("PsHandler.vshost.exe")) { WindowMessage.ShowDialog("Executable file name '" + fi.Name + "' is not default (default: 'PsHandler.exe')." + Environment.NewLine + "Program will quit now.", "Incorrect File Name", WindowMessageButtons.OK, WindowMessageImage.Error, null, WindowStartupLocation.CenterScreen); return; } } catch { } WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator); if (!hasAdministrativeRight) { // relaunch the application with admin rights string fileName = Assembly.GetExecutingAssembly().Location; ProcessStartInfo processInfo = new ProcessStartInfo { Verb = "runas", FileName = fileName }; try { Process.Start(processInfo); } catch { } } else { new App().Run(); } }
private void QueriesView_OnErrorMessage(object sender, MetadataStructureItemErrorEventArgs eventArgs) { var wMessage = new WindowMessage { Owner = this, Text = eventArgs.Message, WindowStartupLocation = WindowStartupLocation.CenterOwner, Title = "UserQueries error" }; var buttonOk = new Button { Content = "OK", HorizontalAlignment = HorizontalAlignment.Center, Width = 75 }; buttonOk.Click += delegate { wMessage.Close(); }; wMessage.Buttons.Add(buttonOk); wMessage.ShowDialog(); }
private void GenerateLayout() { if (!IsVisible) { return; } System.Drawing.Rectangle workingArea = GetWorkingArea(); bool fitByWidth = FitByWidth; bool fitByHeight = FitByHeight; bool fixedTableSize = FixedTableSize; int columns = 1; int rows = 1; bool horizontalAlignmentLeft = HorizontalAlignmentLeft; bool horizontalAlignmentCenter = HorizontalAlignmentCenter; bool horizontalAlignmentRight = HorizontalAlignmentRight; bool horizontalAlignmentStretch = HorizontalAlignmentStretch; bool verticalAlignmentTop = VerticalAlignmentTop; bool verticalAlignmentCenter = VerticalAlignmentCenter; bool verticalAlignmentBottom = VerticalAlignmentBottom; bool verticalAlignmentStretch = VerticalAlignmentStretch; // parse data try { columns = int.Parse(TextBox_TableColumns.Text); if (columns <= 0) { throw new NotSupportedException(); } } catch (Exception) { //WindowMessage.ShowDialog("Invalid input: columns", "Error", WindowMessageButtons.OK, WindowMessageImage.Error, this, WindowStartupLocation.CenterOwner, WindowMessageTextType.TextBlock); return; } try { rows = int.Parse(TextBox_TableRows.Text); if (rows <= 0) { throw new NotSupportedException(); } } catch (Exception) { //WindowMessage.ShowDialog("Invalid input: rows", "Error", WindowMessageButtons.OK, WindowMessageImage.Error, this, WindowStartupLocation.CenterOwner, WindowMessageTextType.TextBlock); return; } // get wanted table size var adjustedWindowSize = new System.Windows.Size(0, 0); if (!fixedTableSize) { var wantedWindowSize = new System.Windows.Size((double)workingArea.Width / columns, (double)workingArea.Height / rows); var wantedClientSize = new System.Windows.Size(wantedWindowSize.Width - WindowsBorderThicknessInPixelsLeft - WindowsBorderThicknessInPixelsRight, wantedWindowSize.Height - WindowsBorderThicknessInPixelsTop - WindowsBorderThicknessInPixelsBottom); // validate table size if (wantedClientSize.Width < PokerStarsThemeTable.WIDTH_MIN) { wantedClientSize.Width = (int)PokerStarsThemeTable.WIDTH_MIN; } if (wantedClientSize.Height < PokerStarsThemeTable.HEIGHT_MIN) { wantedClientSize.Height = (int)PokerStarsThemeTable.HEIGHT_MIN; } if (wantedClientSize.Width > PokerStarsThemeTable.WIDTH_MAX) { wantedClientSize.Width = (int)PokerStarsThemeTable.WIDTH_MAX; } if (wantedClientSize.Height > PokerStarsThemeTable.HEIGHT_MAX) { wantedClientSize.Height = (int)PokerStarsThemeTable.HEIGHT_MAX; } var adjustedClientSize = new System.Drawing.Size(0, 0); if (fitByWidth) { adjustedClientSize = PokerStarsThemeTable.GetClientSizeByWidth((int)Math.Round(wantedClientSize.Width)); } if (fitByHeight) { adjustedClientSize = PokerStarsThemeTable.GetClientSizeByHeight((int)Math.Round(wantedClientSize.Height)); } if (adjustedClientSize.IsEmpty) { throw new NotSupportedException(); } adjustedWindowSize = new System.Windows.Size(adjustedClientSize.Width + WindowsBorderThicknessInPixelsLeft + WindowsBorderThicknessInPixelsRight, adjustedClientSize.Height + WindowsBorderThicknessInPixelsTop + WindowsBorderThicknessInPixelsBottom); } else { try { adjustedWindowSize = new System.Windows.Size(int.Parse(TextBox_TableWidth.Text), int.Parse(TextBox_TableHeight.Text)); var adjustedClientSize = new System.Windows.Size(adjustedWindowSize.Width - WindowsBorderThicknessInPixelsLeft - WindowsBorderThicknessInPixelsRight, adjustedWindowSize.Height - WindowsBorderThicknessInPixelsTop - WindowsBorderThicknessInPixelsBottom); if (adjustedClientSize.Width < PokerStarsThemeTable.WIDTH_MIN || adjustedClientSize.Width > PokerStarsThemeTable.WIDTH_MAX || adjustedClientSize.Height < PokerStarsThemeTable.HEIGHT_MIN || adjustedClientSize.Height > PokerStarsThemeTable.HEIGHT_MAX) { throw new NotSupportedException(); } } catch (Exception) { WindowMessage.ShowDialog("Invalid input: table width/height", "Error", WindowMessageButtons.OK, WindowMessageImage.Error, this, WindowStartupLocation.CenterOwner, WindowMessageTextType.TextBlock); return; } } // place tables double axisHorizontalLeft = workingArea.Left + (double)adjustedWindowSize.Width / 2; double axisHorizontalRight = workingArea.Right - (double)adjustedWindowSize.Width / 2; double axisVerticalTop = workingArea.Top + (double)adjustedWindowSize.Height / 2; double axisVerticalBottom = workingArea.Bottom - (double)adjustedWindowSize.Height / 2; // adjust by alignments bool overlappedHorizontal = adjustedWindowSize.Width * columns > workingArea.Width; bool overlappedVertical = adjustedWindowSize.Height * rows > workingArea.Height; if (!overlappedHorizontal) { if (horizontalAlignmentLeft) { axisHorizontalLeft = workingArea.Left + adjustedWindowSize.Width / 2; axisHorizontalRight = axisHorizontalLeft + adjustedWindowSize.Width * (columns - 1); } if (horizontalAlignmentRight) { axisHorizontalRight = workingArea.Right - adjustedWindowSize.Width / 2; axisHorizontalLeft = axisHorizontalRight - adjustedWindowSize.Width * (columns - 1); } if (horizontalAlignmentCenter) { axisHorizontalLeft = (workingArea.Left + workingArea.Width / 2) - (adjustedWindowSize.Width * (columns - 1) / 2); axisHorizontalRight = (workingArea.Left + workingArea.Width / 2) + (adjustedWindowSize.Width * (columns - 1) / 2); } } if (!overlappedVertical) { if (verticalAlignmentTop) { axisVerticalTop = workingArea.Top + adjustedWindowSize.Height / 2; axisVerticalBottom = axisVerticalTop + adjustedWindowSize.Height * (rows - 1); } if (verticalAlignmentBottom) { axisVerticalBottom = workingArea.Bottom - adjustedWindowSize.Height / 2; axisVerticalTop = axisVerticalBottom - adjustedWindowSize.Height * (rows - 1); } if (verticalAlignmentCenter) { axisVerticalTop = (workingArea.Top + workingArea.Height / 2) - (adjustedWindowSize.Height * (rows - 1) / 2); axisVerticalBottom = (workingArea.Top + workingArea.Height / 2) + (adjustedWindowSize.Height * (rows - 1) / 2); } } // create table center points double axisColumnWidth = 0; double axisRowHeight = 0; if (columns > 1) { axisColumnWidth = (axisHorizontalRight - axisHorizontalLeft) / (columns - 1); } if (rows > 1) { axisRowHeight = (axisVerticalBottom - axisVerticalTop) / (rows - 1); } var pointsCentered = new List <System.Windows.Point>(); for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { pointsCentered.Add(new System.Windows.Point ( axisHorizontalLeft + axisColumnWidth * column, axisVerticalTop + axisRowHeight * row )); } } // create rectangles var rects = new List <System.Drawing.Rectangle>(); foreach (var pointCentered in pointsCentered) { rects.Add(new System.Drawing.Rectangle ( (int)Math.Round(pointCentered.X - adjustedWindowSize.Width / 2), (int)Math.Round(pointCentered.Y - adjustedWindowSize.Height / 2), (int)Math.Round(adjustedWindowSize.Width), (int)Math.Round(adjustedWindowSize.Height) )); } // printout TextBox_TableWidth.Text = string.Format("{0}", adjustedWindowSize.Width); TextBox_TableHeight.Text = string.Format("{0}", adjustedWindowSize.Height); var sb = new StringBuilder(); foreach (var rect in rects) { sb.AppendLine(string.Format("{0} {1} {2} {3}", rect.Left, rect.Top, rect.Width, rect.Height)); } TextBox_XYWidthHeight.Text = ""; TextBox_XYWidthHeight.Text = sb.ToString(); }
private void Button_OK_Click(object sender, RoutedEventArgs e) { if (TextBox_Name.Text.Length == 0) { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", Label_Name.Content), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } if (App.TableTileManager.GetTableTilesCopy().Any(o => o.Name.ToLowerInvariant().Equals(TextBox_Name.Text.ToLowerInvariant()))) { WindowMessage.ShowDialog("Cannot save. Duplicate names.", "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } System.Drawing.Rectangle[] xywhs = GetXYWHs(); if (xywhs == null) { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", "X Y Width Height"), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } try { new Regex(TextBox_RegexWindowTitle.Text); } catch { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", Label_RegexWindowTitle.Content), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } try { new Regex(TextBox_RegexWindowClass.Text); } catch { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", Label_RegexWindowClass.Content), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } try { if (TextBox_TableCountEqualOrGreaterThan.Text.Length > 0) { TableTile.TableCountEqualOrGreaterThan = int.Parse(TextBox_TableCountEqualOrGreaterThan.Text); } else { TableTile.TableCountEqualOrGreaterThan = 1; } } catch { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", TextBox_TableCountEqualOrGreaterThan.Text), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } try { if (TextBox_TableCountEqualOrLessThan.Text.Length > 0) { TableTile.TableCountEqualOrLessThan = int.Parse(TextBox_TableCountEqualOrLessThan.Text); } else { TableTile.TableCountEqualOrLessThan = 100; } } catch { WindowMessage.ShowDialog(string.Format("Invalid '{0}' input.", TextBox_TableCountEqualOrLessThan.Text), "Error saving", WindowMessageButtons.OK, WindowMessageImage.Error, this); return; } TableTile.Name = TextBox_Name.Text; TableTile.KeyCombination = TextBoxHotkey_Hotkey.KeyCombination; TableTile.SortByStartingHand = CheckBox_SortTournamentsByStartingTime.IsChecked == true; TableTile.BringToFront = CheckBox_BringToFront.IsChecked == true; TableTile.RegexWindowTitle = new Regex(TextBox_RegexWindowTitle.Text); TableTile.RegexWindowClass = new Regex(TextBox_RegexWindowClass.Text); TableTile.XYWHs = xywhs; TableTile.AutoTile = CheckBox_EnableAutoTile.IsChecked == true; TableTile.AutoTileMethod = RadioButton_ToTheTop.IsChecked == true ? AutoTileMethod.ToTheTopSlot : RadioButton_ToTheClosest.IsChecked == true ? AutoTileMethod.ToTheClosestSlot : /*unknown default = to the top slot*/ AutoTileMethod.ToTheTopSlot; Saved = true; Close(); }
/// <summary> /// Вызывает окно с сообщением. /// </summary> /// <param name="title">Заголовок окна</param> /// <param name="message">Текст сообщения</param> public static void CallWindowMessage(string title, string message) { WindowMessage winMessage = new WindowMessage(title, message); winMessage.ShowDialog(); }