string color

to set different color to string in a array of string

Page 1 of 1

4 Replies - 46916 Views - Last Post: 13 May 2008 - 07:36 AM Rate Topic: -----

#1 hemakumar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-May 08

string color

Post icon  Posted 13 May 2008 - 05:03 AM

how can i set different color to string in an array of string

i mean, in the string array

string[] str={"hi","hello"};

i want
str[0] --> in red color
str[1] --> in blue color

and i am using richtextbox to display the string array

This post has been edited by hemakumar: 14 May 2008 - 02:13 AM

Is This A Good Question/Topic? 0
  • +

Replies To: string color

#2 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: string color

Posted 13 May 2008 - 06:02 AM

I would use an Arraylist


ArrayList arrayList = new ArrayList();

arrayList.Add(System.Drawing.Color.Red);
arrayList.Add(System.Drawing.Color.Blue);



but if you want to use a string value then



string[] str = string[2];

str[0] = System.Drawing.Color.Red.ToString();
str[1] = System.Drawing.Color.Blue.ToString();


Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 260
  • View blog
  • Posts: 1,419
  • Joined: 07-April 08

Re: string color

Posted 13 May 2008 - 07:03 AM

View Postzakary, on 13 May, 2008 - 06:02 AM, said:

I would use an Arraylist


ArrayList arrayList = new ArrayList();

arrayList.Add(System.Drawing.Color.Red);
arrayList.Add(System.Drawing.Color.Blue);



but if you want to use a string value then



string[] str = string[2];

str[0] = System.Drawing.Color.Red.ToString();
str[1] = System.Drawing.Color.Blue.ToString();



I would think that to make the color of hi red you would manipulate it outside of the array. Not sure if you can change the color while its inside the array.
Was This Post Helpful? 0
  • +
  • -

#4 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: string color

Posted 13 May 2008 - 07:18 AM

I read this

Quote

how can i set different color to string in an array of string
as he wants an array of colors in a string. Now to set "hi" to red in a RichTextBox, when you add the text to it you will have to sets its font color then

This post has been edited by zakary: 13 May 2008 - 07:19 AM

Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5643
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: string color

Posted 13 May 2008 - 07:36 AM

View Postzakary, on 13 May, 2008 - 10:18 AM, said:

I read this

Quote

how can i set different color to string in an array of string
as he wants an array of colors in a string. Now to set "hi" to red in a RichTextBox, when you add the text to it you will have to sets its font color then


Sorry, I read this:

View Posthemakumar, on 13 May, 2008 - 08:03 AM, said:

i want
str[0] --> in red color
str[1] --> in blue color
and i am using ritchtextbox to display the string array


As wanting strings to have color. :P

hemakumar, a string is a simple value, it has no color property. You could make a class to pair up a string value and a color value for rendering in a rich text box. The control itself has the color. e.g.

richTextBox1.Text = "";
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = str[0];
richTextBox1.SelectedText = " ";
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = str[1];



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1