Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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();
        }