I am doing a college project and need to display client status in form of coloured * by using an enum with flags...Now i know how the enum works but the problem is I need to show more than one * within the same field (lable or anything else) but each * with a different colour according to the creteria... Now i cant use label.forecolour cause that sets the whole lables' colour... Can anyone give me some advise?

Is it essental to use a single label? Labels don't have support for multicoloured text, so you can either create a custom user control or override the paint event to draw the *'s in different colours yourself.

It would be easier to have different labels that you simply set to visible = true to show different colours.

Thnx and yes it is essential to use only one label. I'll have a look into the paint event although i have no clue to how to use it or even what it is. Tnx Again!

//attach event handler to Paint event in designer
this.label1.Paint += new System.Windows.Forms.PaintEventHandler(this.label1_Paint);

//then handle the event in code
private void label1_Paint(object sender, PaintEventArgs e)
{
            label1.Text = "";
            label1.AutoSize = false;
            int width = (int)e.Graphics.MeasureString("*", f).Width;
            Font f = ((Label)sender).Font;

            label1.Width = (width * 3);

            Rectangle rect = e.ClipRectangle;
            e.Graphics.DrawString("*", f, Brushes.Red, rect);

            rect.X += width;
            rect.Width -= width;
            e.Graphics.DrawString("*", f, Brushes.Blue, rect);

            rect.X += width;
            rect.Width -= width;
            e.Graphics.DrawString("*", f, Brushes.Yellow, rect); }

That prints three asterix's...should you give you a starting point.

Comments
yeah especially after serkan left
Glad to see another C# Solver on board!
Nice :)

According to the criteria Just try dynamic label control like this,

label local_label = new label();
label.forecolor = red;
label.ID = creating with that particular enum value.

Thx
Chandru
SNIP

Edited 7 Years Ago by happygeek: fake sig snipped

Very nice code Ryshad!
You only should swap line 9 and 10 otherwise f is used before it is defined.

Edited 7 Years Ago by ddanbe: n/a

well spotted :p
I originally used it further down, but moved it up to measure the string to set the label width and forgot to move the assignment with it : /

And thanks, i've been helped out twice now, wanted to give something back to the community :D

Tnx for all the replys so far...haven't got it right though yet...but will let know when i got it working. i really apreciate all the input, tnx.

Tnx for all the input....i misunderstood the question myself...They told me today the single field was intended for the database(which i already had)....sorry for the troubles....i'm using seperate labels now for each status, and tnx again!

This question has already been answered. Start a new discussion instead.