i've a question related to this post: RELATED POST. Can anyone explain how this rectangle area works?
I would like a property that can manipulate the highlight text color, i've tried editing the posted code without successo tho :(
i've a question related to this post: RELATED POST. Can anyone explain how this rectangle area works?
I would like a property that can manipulate the highlight text color, i've tried editing the posted code without successo tho :(
I might have found a solution, but i don't like it very much, i feel like is just a shortcut. So i basically just add my Property 'selectionColor'
private Color selectionColor = Color.Blue;
[DefaultValue(typeof(Color), "LightBlue")]
public Color SelectionColor
{
get { return selectionColor; }
set
{
if (selectionColor != value)
{
selectionColor = value;
Invalidate();
}
}
}
then on the override WndProc function, added this
var selectionColor = Enabled ? SelectionColor : SystemColors.Highlight;
the problem is here, i just tried to copy what the other guy did, but this need a different rectangle area, any way i tried this
using (var s = new SolidBrush(selectionColor))
{
g.FillRectangle(s, "Here should go the rectangle area, but i can't figure out how to get it");
}
At this point i've thought that i could just use that propery to easly change the color. So in the project that im working on i've the DrawItem event, and there did manage to change the highlight text color on a normal combobox. Here's the code:
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
try
{
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.Graphics.FillRectangle(new SolidBrush(**customComboBox1.SelectionColor**), e.Bounds);
}
else
{
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
}
e.Graphics.DrawString(((ComboBox)sender).Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Black), new Point(e.Bounds.X, e.Bounds.Y));
}
catch (Exception)
{
}
}
This works fine, but i am sure there's a way to avoid using drawitem event and just select the color from the properties