Пример #1
0
        //=------------------------------------------------------------------=
        // addColorsToList
        //=------------------------------------------------------------------=
        /// <summary>
        ///   Given an object with a tonne of static color objects, go and
        ///   get those and add them to the list of colors.  We will also
        ///   do an optimisation, and select the appropriate color if it's
        ///   in our list.
        /// </summary>
        ///
        /// <param name="in_listBox">
        ///   Where to add the colors.
        /// </param>
        ///
        /// <param name="in_colorSource">
        ///   From which class to get the colors.
        /// </param>
        ///
        /// <param name="in_selectMe">
        ///   Indicates which color to select when showing the list.
        /// </param>
        ///
        private void addColorsToList
        (
            ListBox in_listBox,
            Type in_colorSource,
            Color in_selectMe
        )
        {
            System.Reflection.PropertyInfo[] pic;
            ColorAndNameListItem             canli;
            int i;

            pic = in_colorSource.GetProperties();

            //
            // Loop through all the properties looking for Color properties.
            //
            foreach (System.Reflection.PropertyInfo pi in pic)
            {
                if (pi.PropertyType == typeof(Color))
                {
                    canli       = new ColorAndNameListItem();
                    canli.Color = (Color)pi.GetValue(null, null);
                    canli.Name  = pi.Name;

                    i = in_listBox.Items.Add(canli);
                    if (in_selectMe.Equals(canli.Color))
                    {
                        in_listBox.SelectedIndex = i;
                    }
                }
            }
        }
Пример #2
0
        //=------------------------------------------------------------------=
        // populateAndSelectColorList
        //=------------------------------------------------------------------=
        /// <summary>
        ///   Sets up an owner draw listbox to contain most of the interesting
        ///   colors currently available on the system.  It will then select
        ///   the given color.
        /// </summary>
        ///
        /// <param name="in_listBox">
        ///   The owner-draw ListBox to populate.
        /// </param>
        ///
        /// <param name="in_selectMe">
        ///   The Color to select.
        /// </param>
        ///
        /// <param name="in_resources">
        ///   From where to get localized strings.
        /// </param>
        ///
        private void populateAndSelectColorList
        (
            ListBox in_listBox,
            Color in_selectMe,
            System.Resources.ResourceManager in_resources
        )
        {
            ColorAndNameListItem canli = new ColorAndNameListItem();
            string s;

            //
            // 1. Add SystemColors to list box.  Please note that we'r
            //    going to pass in the color to select so that we can
            //    compare against the colors in their native format, and
            //    not have to go back and  regenerate the colors from
            //    the type strings, etc ...
            //
            addColorsToList(in_listBox, typeof(SystemColors), in_selectMe);

            //
            // 2. Add Regular colors to the list box.
            //
            addColorsToList(in_listBox, typeof(Color), in_selectMe);

            //
            // 3. If the user gave us a color that isn't one of the predefined
            //    system-y colors, then go and add a "Custom" entry for their
            //    color.
            //
            if (in_listBox.SelectedIndex == -1)
            {
                s = in_resources.GetString("customColor");
                System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(s));

                canli       = new ColorAndNameListItem();
                canli.Color = in_selectMe;
                canli.Name  = s;

                in_listBox.Items.Insert(0, canli);
                in_listBox.SelectedIndex = 0;
            }
        }