Click here to Skip to main content
15,920,596 members
Home / Discussions / C#
   

C#

 
AnswerRe: Multicore/multithread Pin
Simon P Stevens20-Oct-08 23:32
Simon P Stevens20-Oct-08 23:32 
QuestionOLE Server in C# Pin
VasDemidov20-Oct-08 23:01
VasDemidov20-Oct-08 23:01 
AnswerRe: OLE Server in C# Pin
Abdallah Gomah5-Apr-10 18:26
Abdallah Gomah5-Apr-10 18:26 
QuestionHow can I programmatically generate OnDrawItem events for a ComboBox? Pin
arnold_w20-Oct-08 22:50
arnold_w20-Oct-08 22:50 
AnswerRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
Simon P Stevens20-Oct-08 22:57
Simon P Stevens20-Oct-08 22:57 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
arnold_w20-Oct-08 23:15
arnold_w20-Oct-08 23:15 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
leppie20-Oct-08 23:25
leppie20-Oct-08 23:25 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
Simon P Stevens20-Oct-08 23:36
Simon P Stevens20-Oct-08 23:36 
Ahh, I see what you're trying to do.

You shouldn't really be calling OnDrawItem yourself. The idea is that the method is called automatically whenever windows needs to draw the item. You then intercept that with your override and perform the customised drawing.

Like Leppie says, you need to enable owner drawing for the method to be triggers. This bit of sample code draws the items in red.
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        CreateComboBox();
    }

    private void CreateComboBox()
    {
        MyCombo cbox = new MyCombo();
        cbox.DrawMode = DrawMode.OwnerDrawFixed;

        cbox.Items.Add("test1");
        cbox.Items.Add("test2");

        this.Controls.Add(cbox);
    }
}

public class MyCombo : ComboBox
{
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        e.DrawBackground();
        e.DrawFocusRectangle();


        String item = (String)this.Items[e.Index];

        Debug.WriteLine("drawing: " + item);
        e.Graphics.DrawString(item, e.Font, Brushes.Red, e.Bounds.Location);
        base.OnDrawItem(e);
    }
}


(Set it to fixed or variable, depending on the type of custom drawing you plan on doing)

Simon

GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
arnold_w21-Oct-08 0:09
arnold_w21-Oct-08 0:09 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
Simon P Stevens21-Oct-08 0:22
Simon P Stevens21-Oct-08 0:22 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
arnold_w21-Oct-08 0:26
arnold_w21-Oct-08 0:26 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
leppie21-Oct-08 0:30
leppie21-Oct-08 0:30 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
arnold_w21-Oct-08 0:48
arnold_w21-Oct-08 0:48 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
leppie21-Oct-08 0:51
leppie21-Oct-08 0:51 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
arnold_w21-Oct-08 0:58
arnold_w21-Oct-08 0:58 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
Simon P Stevens21-Oct-08 0:58
Simon P Stevens21-Oct-08 0:58 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
arnold_w21-Oct-08 1:01
arnold_w21-Oct-08 1:01 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
Simon P Stevens21-Oct-08 1:07
Simon P Stevens21-Oct-08 1:07 
GeneralRe: How can I programmatically generate OnDrawItem events for a ComboBox? Pin
leppie21-Oct-08 3:20
leppie21-Oct-08 3:20 
QuestionKilling a Process Pin
Vimalsoft(Pty) Ltd20-Oct-08 22:38
professionalVimalsoft(Pty) Ltd20-Oct-08 22:38 
AnswerRe: Killing a Process Pin
Simon P Stevens20-Oct-08 22:51
Simon P Stevens20-Oct-08 22:51 
AnswerRe: Killing a Process Pin
Vimalsoft(Pty) Ltd21-Oct-08 20:03
professionalVimalsoft(Pty) Ltd21-Oct-08 20:03 
QuestionHow to alter the main GUI from another class/object? Pin
munk1220-Oct-08 21:55
munk1220-Oct-08 21:55 
AnswerRe: How to alter the main GUI from another class/object? Pin
leppie20-Oct-08 21:57
leppie20-Oct-08 21:57 
GeneralRe: How to alter the main GUI from another class/object? Pin
munk1221-Oct-08 23:42
munk1221-Oct-08 23:42 

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.