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

C#

 
AnswerRe: I got this error on page load my photo gallery page . http://s.codeproject.com/script/Forums/Images/smiley_WTF.gif Pin
OriginalGriff25-Apr-14 23:18
mveOriginalGriff25-Apr-14 23:18 
QuestionHow can I change the background color of the part of a ComboBox that is always visible? Pin
arnold_w25-Apr-14 4:34
arnold_w25-Apr-14 4:34 
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 
It only seem to work if the DropDownStyle is set to DropDownList; I don't think you can owner-draw the edit box of an editable ComboBox.

The State property can combine multiple values, so you can't do a straight equality test. You'll need to use the HasFlag method[^] instead.

Your code also won't draw anything until you select an item from the list. If you want to see the custom background colour even when you haven't selected an item, you'll need to remove the initial e.Index test, and add a conditional test around the DrawString line:
C#
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    var control = (ComboBox)sender;

    if (e.State.HasFlag(DrawItemState.ComboBoxEdit))
    {
        e.Graphics.FillRectangle(Brushes.Violet, e.Bounds);
    }
    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: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 
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 

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.