/// <summary> /// The add color to recent colors if missing. /// </summary> /// <param name="color"> /// The color. /// </param> /// <returns> /// True if the color was added. /// </returns> private bool AddColorToRecentColorsIfMissing(Color color) { // Check if the color exists if (ThemeColors.Contains(color)) { return(false); } if (StandardColors.Contains(color)) { return(false); } if (RecentColors.Contains(color)) { return(false); } if (RecentColors.Count >= this.MaxNumberOfRecentColors) { RecentColors.RemoveAt(RecentColors.Count - 1); } RecentColors.Insert(0, color); return(true); }
private void OnLoaded(object sender, RoutedEventArgs e) { if (!(GetTemplateChild("PART_MoreColors") is FluentMenuItem moreColors)) { return; } EventManager.RegisterClassHandler(moreColors.GetType(), MenuItem.ClickEvent, new RoutedEventHandler((s, args) => { if (moreColors != s) { return; } var colorChoose = new ColorChooserWindow { Owner = Window.GetWindow(this) }; colorChoose.ActionComplete += (o, eventArgs) => { var color = eventArgs.Color; if (RecentColors.Contains(color)) { RecentColors.Remove(color); } RecentColors.Insert(0, color); if (GetTemplateChild("PART_RecentColorsListBox") is ListBox recentColors) { recentColors.SelectedIndex = 0; } }; colorChoose.ShowDialog(); args.Handled = true; })); }
private void OnMoreColorsClick(object sender, RoutedEventArgs e) { if (this.MoreColorsExecuting != null) { var args = new MoreColorsExecutingEventArgs(); this.MoreColorsExecuting(this, args); if (!args.Canceled) { var color = args.Color; if (RecentColors.Contains(color)) { RecentColors.Remove(color); } RecentColors.Insert(0, color); this.recentColorsListBox.SelectedIndex = 0; } } else { #pragma warning disable 618 var chooseColor = new CHOOSECOLOR(); var wnd = Window.GetWindow(this); if (wnd != null) { chooseColor.hwndOwner = new WindowInteropHelper(wnd).Handle; } chooseColor.Flags = CC_ANYCOLOR; if (customColors == IntPtr.Zero) { // Set custom colors) for (var i = 0; i < this.colorsArray.Length; i++) { this.colorsArray[i] = 0x00FFFFFF; } customColors = GCHandle.Alloc(this.colorsArray, GCHandleType.Pinned).AddrOfPinnedObject(); } chooseColor.lpCustColors = customColors; if (ChooseColor(chooseColor)) { var color = ConvertFromWin32Color(chooseColor.rgbResult); if (RecentColors.Contains(color)) { RecentColors.Remove(color); } RecentColors.Insert(0, color); this.recentColorsListBox.SelectedIndex = 0; } #pragma warning restore 618 } }
private void UpdateRecentColors(ColorItem colorItem) { if (!RecentColors.Contains(colorItem)) { RecentColors.Add(colorItem); } if (RecentColors.Count > 10) //don't allow more than ten, maybe make a property that can be set by the user. { RecentColors.RemoveAt(0); } }
private void OnMoreColorsClick(object sender, RoutedEventArgs e) { if (MoreColorsExecuting != null) { MoreColorsExecutingEventArgs args = new MoreColorsExecutingEventArgs(); MoreColorsExecuting(this, args); if (!args.Canceled) { Color color = args.Color; if (RecentColors.Contains(color)) { RecentColors.Remove(color); } RecentColors.Insert(0, color); recentColorsListBox.SelectedIndex = 0; } } else { NativeMethods.CHOOSECOLOR chooseColor = new NativeMethods.CHOOSECOLOR(); Window wnd = Window.GetWindow(this); if (wnd != null) { chooseColor.hwndOwner = new WindowInteropHelper(wnd).Handle; } chooseColor.Flags = NativeMethods.CC_ANYCOLOR; if (customColors == IntPtr.Zero) { // Set custom colors) for (int i = 0; i < colorsArray.Length; i++) { colorsArray[i] = 0x00FFFFFF; } customColors = GCHandle.Alloc(colorsArray, GCHandleType.Pinned).AddrOfPinnedObject(); } chooseColor.lpCustColors = customColors; if (NativeMethods.ChooseColor(chooseColor)) { Color color = ConvertFromWin32Color(chooseColor.rgbResult); if (RecentColors.Contains(color)) { RecentColors.Remove(color); } RecentColors.Insert(0, color); recentColorsListBox.SelectedIndex = 0; } } }
/// <summary> /// The add color to recent colors if missing. /// </summary> /// <param name="color">The color.</param> private void AddColorToRecentColorsIfMissing(Color color) { // Check if the color exists if (RecentColors.Contains(color)) { var index = RecentColors.IndexOf(color); RecentColors.Move(index, 0); return; } if (RecentColors.Count >= this.MaxNumberOfRecentColors) { RecentColors.RemoveAt(RecentColors.Count - 1); } RecentColors.Insert(0, color); }
private static ConsoleColor GetGoodConsoleColor() { int[] goodConsoleColours = { 10, 11, 12, 13, 14, 15 }; //Green = 10,Cyan = 11,Red = 12,Magenta = 13,Yellow = 14, White = 15 ConsoleColor color; do { int randomNumber = new Random().Next(); color = (ConsoleColor)goodConsoleColours[randomNumber % goodConsoleColours.Length]; } while (RecentColors.Contains(color)); AddColorUsage(color); return(color); }
private static void Main(string[] args) { // Inline Color Picker // https://marketplace.visualstudio.com/items?itemName=NikolaMSFT.InlineColorPicker // を入れるとカラフルな上 変更も簡単で超おすすめ // xaml用だと思ってたらどこでも効くっていう // 空で生成 var c = new RecentColors(); Console.WriteLine(c); // string.Empty // サイズ指定&空で生成 c = new RecentColors(2); Console.WriteLine(c); // string.Empty // 文字列から生成 c = new RecentColors("Red, #00F"); Console.WriteLine(c); // Red, #0000FF // サイズ指定&文字列から生成 c = new RecentColors(1, "Red, #00F"); Console.WriteLine(c); // #0000FF // コレクション初期化子で生成 // 注)名前付きとHexは別扱い(Colorの等値判定に準ずる) c = new RecentColors { Color.Red, Color.Red, ColorTranslator.FromHtml("#f00"), ColorTranslator.FromHtml("#ff0000"), }; Console.WriteLine(c); // Red, #FF0000 // サイズ指定&コレクション初期化子で生成 c = new RecentColors(1) { Color.Red, ColorTranslator.FromHtml("#f00"), }; Console.WriteLine(c); // #FF0000 var r = new RecentColors("#000, #F00, #0F0"); Console.WriteLine(r); // #000000, #FF0000, #00FF00 // 追加 c.Add(ColorTranslator.FromHtml("#00F")); Console.WriteLine(r); // #000000, #FF0000, #00FF00, #0000FF // リミット変更 r.Limit = 2; Console.WriteLine(r); // #00FF00, #0000FF // 同値の追加 r.Add(ColorTranslator.FromHtml("#0F0")); Console.WriteLine(r); // #0000FF, #00FF00 // 不正文字列はスルーする c = new RecentColors("Reed, #00F"); Console.WriteLine(c); // #0000FF Console.ReadKey(); }