Click here to Skip to main content
15,879,613 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 15:37
professionalRichard Andrew x6428-Aug-12 15:37 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 15:52
turbosupramk328-Aug-12 15:52 
GeneralRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 15:58
professionalRichard Andrew x6428-Aug-12 15:58 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 16:04
turbosupramk328-Aug-12 16:04 
GeneralRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 16:08
professionalRichard Andrew x6428-Aug-12 16:08 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 16:15
turbosupramk328-Aug-12 16:15 
AnswerRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 16:28
professionalRichard Andrew x6428-Aug-12 16:28 
GeneralRe: How can I change this event handler? Pin
turbosupramk328-Aug-12 16:47
turbosupramk328-Aug-12 16:47 
Thanks for the code, I will try that tomorrow.

One more question, with the code block below, how do I integrate or manipulate the e.index portion of it, so I can set it before calling the two method examples you provided?

C#
public FormMain()
        {
            InitializeComponent();
            listBox.DrawMode = DrawMode.OwnerDrawFixed;
            listBox.DrawItem += new DrawItemEventHandler(listBox_DrawItem);
            listBox.Items.AddRange(new object[] { "A", "B", "C" });
        }




Quote:
private string GetColorForItem( int Index )
{
// return correct color name
}

private string GetStringForItem( int Index )
{
// return correct string
}

void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index > -1)
{
string colorToUse = GetColorForItem(e.Index);
string textToUse = GetStringForItem(e.Index);

if (colorToUse == "red")
e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
else if (colorToUse == "green")
e.Graphics.FillRectangle(Brushes.Green, e.Bounds);
else
e.DrawBackground();

using (Brush textBrush = new SolidBrush(e.ForeColor))
{
e.Graphics.DrawString(textToUse, e.Font, textBrush, e.Bounds.Location);
}
}
}

AnswerRe: How can I change this event handler? Pin
Richard Andrew x6428-Aug-12 16:55
professionalRichard Andrew x6428-Aug-12 16:55 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 4:29
turbosupramk329-Aug-12 4:29 
AnswerRe: How can I change this event handler? Pin
BobJanova28-Aug-12 23:14
BobJanova28-Aug-12 23:14 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 4:28
turbosupramk329-Aug-12 4:28 
GeneralRe: How can I change this event handler? Pin
BobJanova29-Aug-12 4:51
BobJanova29-Aug-12 4:51 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 5:05
turbosupramk329-Aug-12 5:05 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 5:50
turbosupramk329-Aug-12 5:50 
GeneralRe: How can I change this event handler? Pin
BobJanova29-Aug-12 6:25
BobJanova29-Aug-12 6:25 
GeneralRe: How can I change this event handler? Pin
turbosupramk329-Aug-12 6:48
turbosupramk329-Aug-12 6:48 
GeneralRe: How can I change this event handler? Pin
turbosupramk330-Aug-12 6:37
turbosupramk330-Aug-12 6:37 
QuestionSpeechSynthesizer is too fast Pin
Jassim Rahma28-Aug-12 10:37
Jassim Rahma28-Aug-12 10:37 
AnswerRe: SpeechSynthesizer is too fast Pin
Ravi Bhavnani29-Aug-12 7:31
professionalRavi Bhavnani29-Aug-12 7:31 
QuestionSpecific Fill size Pin
Jassim Rahma28-Aug-12 10:02
Jassim Rahma28-Aug-12 10:02 
AnswerRe: Specific Fill size Pin
Eddy Vluggen28-Aug-12 10:33
professionalEddy Vluggen28-Aug-12 10:33 
AnswerRe: Specific Fill size Pin
BobJanova28-Aug-12 23:15
BobJanova28-Aug-12 23:15 
QuestionUsing UserControls Pin
WebMaster28-Aug-12 9:04
WebMaster28-Aug-12 9:04 
AnswerRe: Using UserControls Pin
Ian Shlasko28-Aug-12 9:26
Ian Shlasko28-Aug-12 9:26 

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.