public ColorFinderWindow () { Title = "Color finder"; StackPanel argb_panel = new StackPanel (); argb_panel.Orientation = Orientation.Horizontal; ArgbInputBox argb_input_box = new ArgbInputBox (); Button find_button = new Button (); find_button.Content = "_Find"; find_button.ToolTip = "Searches the Colors and SystemColors classes for members that have the specified ARGB values. The first item found is copied to clipboard."; find_button.Margin = new Thickness (ElementMargin); find_button.Width = ElementSize; argb_panel.Children.Add (argb_input_box); argb_panel.Children.Add (find_button); ListBox results_list_box = new ListBox (); StackPanel content = new StackPanel (); content.Children.Add (argb_panel); content.Children.Add (new Label ("R_esults (double clicking copies the selected item to clipboard)", results_list_box)); content.Children.Add (results_list_box); ScrollViewer scroll_viewer = new ScrollViewer (); scroll_viewer.Content = content; Content = scroll_viewer; find_button.Click += delegate (object sender, RoutedEventArgs e) { results_list_box.Items.Clear (); byte a, r, g, b; try { a = argb_input_box.A; r = argb_input_box.R; g = argb_input_box.G; b = argb_input_box.B; } catch (FormatException) { MessageBox.Show (this, "One of the values is in the wrong format.", Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } foreach (PropertyInfo property in typeof (Colors).GetProperties ()) { Color color = (Color)property.GetValue (null, null); if (color.A == a && color.R == r && color.G == g && color.B == b) results_list_box.Items.Add ("Colors." + property.Name); } foreach (PropertyInfo property in typeof (SystemColors).GetProperties ()) { if (property.PropertyType == typeof (Color)) { Color color = (Color)property.GetValue (null, null); if (color.A == a && color.R == r && color.G == g && color.B == b) results_list_box.Items.Add ("SystemColors." + property.Name); } } if (results_list_box.Items.Count != 0) Clipboard.SetText ((string)results_list_box.Items [0]); }; results_list_box.MouseDoubleClick += delegate (object sender, MouseButtonEventArgs e) { if (results_list_box.SelectedItem != null) Clipboard.SetText ((string)results_list_box.SelectedItem); }; }
public ColorFinderWindow() { Title = "Color finder"; StackPanel argb_panel = new StackPanel(); argb_panel.Orientation = Orientation.Horizontal; ArgbInputBox argb_input_box = new ArgbInputBox(); Button find_button = new Button(); find_button.Content = "_Find"; find_button.ToolTip = "Searches the Colors and SystemColors classes for members that have the specified ARGB values. The first item found is copied to clipboard."; find_button.Margin = new Thickness(ElementMargin); find_button.Width = ElementSize; argb_panel.Children.Add(argb_input_box); argb_panel.Children.Add(find_button); ListBox results_list_box = new ListBox(); StackPanel content = new StackPanel(); content.Children.Add(argb_panel); content.Children.Add(new Label("R_esults (double clicking copies the selected item to clipboard)", results_list_box)); content.Children.Add(results_list_box); ScrollViewer scroll_viewer = new ScrollViewer(); scroll_viewer.Content = content; Content = scroll_viewer; find_button.Click += delegate(object sender, RoutedEventArgs e) { results_list_box.Items.Clear(); byte a, r, g, b; try { a = argb_input_box.A; r = argb_input_box.R; g = argb_input_box.G; b = argb_input_box.B; } catch (FormatException) { MessageBox.Show(this, "One of the values is in the wrong format.", Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } foreach (PropertyInfo property in typeof(Colors).GetProperties()) { Color color = (Color)property.GetValue(null, null); if (color.A == a && color.R == r && color.G == g && color.B == b) { results_list_box.Items.Add("Colors." + property.Name); } } foreach (PropertyInfo property in typeof(SystemColors).GetProperties()) { if (property.PropertyType == typeof(Color)) { Color color = (Color)property.GetValue(null, null); if (color.A == a && color.R == r && color.G == g && color.B == b) { results_list_box.Items.Add("SystemColors." + property.Name); } } } if (results_list_box.Items.Count != 0) { Clipboard.SetText((string)results_list_box.Items [0]); } }; results_list_box.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) { if (results_list_box.SelectedItem != null) { Clipboard.SetText((string)results_list_box.SelectedItem); } }; }