Click here to Skip to main content
15,889,216 members
Home / Discussions / C#
   

C#

 
QuestionRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
Richard Deeming25-Apr-14 4:52
mveRichard Deeming25-Apr-14 4:52 
AnswerRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
arnold_w25-Apr-14 4:56
arnold_w25-Apr-14 4:56 
GeneralRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
Richard Deeming25-Apr-14 5:10
mveRichard Deeming25-Apr-14 5:10 
GeneralRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
Mycroft Holmes25-Apr-14 13:23
professionalMycroft Holmes25-Apr-14 13:23 
GeneralRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
arnold_w27-Apr-14 21:22
arnold_w27-Apr-14 21:22 
GeneralRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
Richard Deeming28-Apr-14 1:39
mveRichard Deeming28-Apr-14 1:39 
GeneralRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
arnold_w28-Apr-14 2:17
arnold_w28-Apr-14 2:17 
GeneralRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
Richard Deeming28-Apr-14 2:32
mveRichard Deeming28-Apr-14 2:32 
HasFlag was added in .NET 4.0, so I guess you must be using 3.5 or earlier.

The ForeColor property will change depending on whether or not the item is highlighted. If you always want the text to be black, then use Brushes.Black instead.

C#
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    var control = (ComboBox)sender;

    if (0 != (e.State & DrawItemState.ComboBoxEdit))
    {
        e.Graphics.FillRectangle(Brushes.Violet, e.Bounds);
        
        if (e.Index >= 0)
        {
            e.Graphics.DrawString(control.Items[e.Index].ToString(), e.Font,
                Brushes.Black, e.Bounds.X, e.Bounds.Y);
        }
    }
    else
    {
        e.DrawBackground();
        
        if (e.Index >= 0)
        {
            e.Graphics.DrawString(control.Items[e.Index].ToString(), e.Font,
                new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y);
        }
    }

    e.DrawFocusRectangle();
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: How can I change the background color of the part of a ComboBox that is always visible? Pin
arnold_w28-Apr-14 2:35
arnold_w28-Apr-14 2:35 
QuestionHow can I disallow SelectedValue to be -1 in a ComboBox? Pin
arnold_w25-Apr-14 4:28
arnold_w25-Apr-14 4:28 
AnswerRe: How can I disallow SelectedValue to be -1 in a ComboBox? Pin
OriginalGriff25-Apr-14 4:42
mveOriginalGriff25-Apr-14 4:42 
GeneralRe: How can I disallow SelectedValue to be -1 in a ComboBox? Pin
arnold_w25-Apr-14 4:48
arnold_w25-Apr-14 4:48 
GeneralRe: How can I disallow SelectedValue to be -1 in a ComboBox? Pin
OriginalGriff25-Apr-14 5:04
mveOriginalGriff25-Apr-14 5:04 
GeneralRe: How can I disallow SelectedValue to be -1 in a ComboBox? Pin
arnold_w25-Apr-14 5:20
arnold_w25-Apr-14 5:20 
GeneralRe: How can I disallow SelectedValue to be -1 in a ComboBox? Pin
OriginalGriff25-Apr-14 6:00
mveOriginalGriff25-Apr-14 6:00 
Questionadd picturebox to panel from a dll file at design time Pin
Member 1059256824-Apr-14 23:25
Member 1059256824-Apr-14 23:25 
AnswerRe: add picturebox to panel from a dll file at design time Pin
Eddy Vluggen25-Apr-14 4:00
professionalEddy Vluggen25-Apr-14 4:00 
QuestionC# unable to get handle when multiple instances of app are open in windows 8.1 Pin
RRLCoder24-Apr-14 19:11
RRLCoder24-Apr-14 19:11 
QuestionRe: C# unable to get handle when multiple instances of app are open in windows 8.1 Pin
Eddy Vluggen25-Apr-14 4:01
professionalEddy Vluggen25-Apr-14 4:01 
AnswerRe: C# unable to get handle when multiple instances of app are open in windows 8.1 Pin
RRLCoder25-Apr-14 6:44
RRLCoder25-Apr-14 6:44 
GeneralRe: C# unable to get handle when multiple instances of app are open in windows 8.1 Pin
Eddy Vluggen27-Apr-14 9:00
professionalEddy Vluggen27-Apr-14 9:00 
GeneralRe: C# unable to get handle when multiple instances of app are open in windows 8.1 Pin
RRLCoder27-Apr-14 10:49
RRLCoder27-Apr-14 10:49 
QuestionMute other applications Pin
el_stupey24-Apr-14 15:40
el_stupey24-Apr-14 15:40 
AnswerRe: Mute other applications Pin
Mycroft Holmes24-Apr-14 16:17
professionalMycroft Holmes24-Apr-14 16:17 
GeneralRe: Mute other applications Pin
el_stupey26-Apr-14 1:39
el_stupey26-Apr-14 1:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.