Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8023853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:41:16+00:00 2026-06-04T22:41:16+00:00

I have 2 ownerdrawn combo boxes. One is a line color picker- Here in

  • 0

I have 2 ownerdrawn combo boxes.
One is a line color picker- Here in the picture it is not a combo box.
The other being a linestyle selector.
Once the user picks a color in the first combo, the linestyle selector combo (See second picture, the last combo(one with noname))
must have the same colored lines.

enter image description here

Currently it shows like this

enter image description here
Here’s the code for both combos
Linecolor picker

    public partial class ColorPicker : ComboBox
    {
        // Data for each color in the list
        public class ColorInfo
        {
            public string Text { get; set; }
            public Color Color { get; set; }

            public ColorInfo(string text, Color color)
            {
                Text = text;
                Color = color;
            }
        }

        public ColorPicker()
        {
            InitializeComponent();

            DropDownStyle = ComboBoxStyle.DropDownList;
            DrawMode = DrawMode.OwnerDrawFixed;
            DrawItem += OnDrawItem;
        }

        // Populate control with standard colors
        public void AddStandardColors()
        {
            Items.Clear();
            Items.Add(new ColorInfo("Black", Color.Black));
            Items.Add(new ColorInfo("Blue", Color.Blue));
            Items.Add(new ColorInfo("Lime", Color.Lime));
            Items.Add(new ColorInfo("Cyan", Color.Cyan));
            Items.Add(new ColorInfo("Red", Color.Red));
            Items.Add(new ColorInfo("Fuchsia", Color.Fuchsia));
            Items.Add(new ColorInfo("Yellow", Color.Yellow));
            Items.Add(new ColorInfo("White", Color.White));
            Items.Add(new ColorInfo("Navy", Color.Navy));
            Items.Add(new ColorInfo("Green", Color.Green));
            Items.Add(new ColorInfo("Teal", Color.Teal));
            Items.Add(new ColorInfo("Maroon", Color.Maroon));
            Items.Add(new ColorInfo("Purple", Color.Purple));
            Items.Add(new ColorInfo("Olive", Color.Olive));
            Items.Add(new ColorInfo("Gray", Color.Gray));
        }

        // Draw list item
        protected void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index >= 0)
            {
                // Get this color
                ColorInfo color = (ColorInfo)Items[e.Index];

                // Fill background
                e.DrawBackground();

                // Draw color box
                Rectangle rect = new Rectangle();
                rect.X = e.Bounds.X + 2;
                rect.Y = e.Bounds.Y + 2;
                rect.Width = 18;
                rect.Height = e.Bounds.Height - 5;
                e.Graphics.FillRectangle(new SolidBrush(color.Color), rect);
                e.Graphics.DrawRectangle(SystemPens.WindowText, rect);

                // Write color name
                Brush brush;
                if ((e.State & DrawItemState.Selected) != DrawItemState.None)
                    brush = SystemBrushes.HighlightText;
                else
                    brush = SystemBrushes.WindowText;
                e.Graphics.DrawString(color.Text, Font, brush,
                    e.Bounds.X + rect.X + rect.Width + 2,
                    e.Bounds.Y + ((e.Bounds.Height - Font.Height) / 2));

                // Draw the focus rectangle if appropriate
                if ((e.State & DrawItemState.NoFocusRect) == DrawItemState.None)
                    e.DrawFocusRectangle();
            }
        }

        /// <summary>
        /// Gets or sets the currently selected item.
        /// </summary>
        public new ColorInfo SelectedItem
        {
            get
            {
                return (ColorInfo)base.SelectedItem;
            }
            set
            {
                base.SelectedItem = value;
            }
        }

        /// <summary>
        /// Gets the text of the selected item, or sets the selection to
        /// the item with the specified text.
        /// </summary>
        public new string SelectedText
        {
            get
            {
                if (SelectedIndex >= 0)
                    return SelectedItem.Text;
                return String.Empty;
            }
            set
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    if (((ColorInfo)Items[i]).Text == value)
                    {
                        SelectedIndex = i;
                        break;
                    }
                }
            }
        }

        /// <summary>
        /// Gets the value of the selected item, or sets the selection to
        /// the item with the specified value.
        /// </summary>
        public new int SelectedValue
        {
            get
            {
                if (SelectedIndex >= 0)
                    return SelectedItem.Color.ToArgb();
                return Color.White.ToArgb();
            }
            set
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    if (((ColorInfo)Items[i]).Color.ToArgb() == value)
                    {
                        SelectedIndex = i;
                        break;
                    }
                }
            }
        }
    }
}

Code for lineselector combo. This is the last combo(the one with no name) on my second picture. : `


    public partial class comboBoxLineStyle : ComboBox
    {
        public comboBoxLineStyle()
        {
            InitializeComponent();
            this.DrawMode = DrawMode.OwnerDrawFixed;
            this.DropDownStyle = ComboBoxStyle.DropDownList;


        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);

            if (e.Index < 0) { return; }
            e.DrawBackground();
            ComboBoxItem item = (ComboBoxItem)this.Items[e.Index];
           e.Graphics.DrawImage(item.Picture,new Point(e.Bounds.X, e.Bounds.Y));

        }
        public new Image SelectedItem
        {
            get
            {
                return (Image)base.SelectedItem;
            }
            set
            {
                base.SelectedItem = value;
            }
        }
        public new Image SelectedValue
        {
            get
            {
                return (Image)base.SelectedValue;
            }
            set
            {
                base.SelectedValue = value;
            }
        }

    }

    public class ComboBoxItem
    {
        public string text;
        public Image Picture;
        public int foreColor;
        //public override string ToString()
        //{
        //    return text;
        //}

        public ComboBoxItem() { }
        public ComboBoxItem(string pText, Image pValue)
        {
            text = pText;
            Picture = pValue;
        }
        public ComboBoxItem(string pText, Image pValue, int pColor)
        {

            text = pText; Picture = pValue; foreColor = pColor;

        }


    }
}

in the form I am accessing these as follows:

private void DlgGraphOptions_Load(object sender, EventArgs e)
        {

            Color selCol = m_SerOpts.GetColor(idxSeries);
            int selcolARGB = selCol.ToArgb();
            Color color = Color.FromArgb(selcolARGB);

            ComboBoxItem item1Solid = new ComboBoxItem("Solid Line",Properties.Resources.Solidline,selcolARGB);
            ComboBoxItem item1dash = new ComboBoxItem("Dashed Line", Properties.Resources.dashedline,selcolARGB);
            ComboBoxItem item1dashed = new ComboBoxItem("Dashed Line", Properties.Resources.dashdash,selcolARGB);

             comboBoxLineStyle1.Items.Add(item1Solid);
            comboBoxLineStyle1.Items.Add(item1dash);
            comboBoxLineStyle1.Items.Add(item1dashed);
            comboBoxLineStyle1.SelectedIndex = 0;



              //I prefer doing something like this
comboBoxLineStyle1.ForeColor.ToArgb() = selcolARGB .


            }

The m_SerOpts.GetColor(idxSeries) method returns a color object but returns a ’00fff00′ kind of value for Name.
Pls lemme know if u need more explanation

`

Thank u

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:41:18+00:00Added an answer on June 4, 2026 at 10:41 pm

    I would use reflection to populate a list with all colours from the Color class (although you could copy this in code):

    Dictionary<String, Color> colors = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public).ToDictionary(p => p.Name, p => (Color)p.GetValue(null, null) );
    

    then use a method to search this dictionary for a color which matches a passed color:

    public String GetColorName(Color color)
    {
        return colors.Where(c => c.Value.A == color.A && c.Value.R == color.R && c.Value.G == color.G && c.Value.B == color.B).FirstOrDefault().Key;
    }
    

    If no color is matched, null will be returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ownerdrawn ListView that smears when I scroll. It only affects the
Have deployed numerous report parts which reference the same view however one of them
Have an issue with marshall and unmarshall readers and writers. So here it is.
I have a owner drawn control where I need to draw the expand box
Have one Doubt In MVC Architecture we can able to pass data from Controller
I have an Owner Drawn List Box in an external application ( America Online
Have any one tried to activate fancybox thumbnail gallery using a button or an
I have a popup dialog( CDialog ) that handles WM_CTLCOLOR message to color itself.
Have such a problem, hope you'll help me.. Can't find anywhere. Here is the
Have a look at the following code. The goal here is to return a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.