how to use a var in hc.BackColor = Drawing.Color?

D

D.

Hi,

Look at this:
Dim hc As TableHeaderCell
hc = New TableHeaderCell()
hc.BackColor = Drawing.Color.lightGray

My problem is:
i want to put the color into a variable like this:
dim mycolor as string
mycolor="red"
hc.BackColor = Drawing.Color.mycolor

But this doen't work because of the "".
Error: 'mycolor' is not a member of 'System.Drawing.Color'
Any way to do this?
Thanks
D.
 
K

Ken Cox - Microsoft MVP

Hi D,

Try using System.Drawing.ColorTranslator.FromHtml(mycolor)

as in:

Dim mycolor As String = "red"
Label1.BackColor = System.Drawing.ColorTranslator.FromHtml(mycolor)

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 
D

D.

Thanks, it works


Ken Cox - Microsoft MVP said:
Hi D,

Try using System.Drawing.ColorTranslator.FromHtml(mycolor)

as in:

Dim mycolor As String = "red"
Label1.BackColor = System.Drawing.ColorTranslator.FromHtml(mycolor)

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


D. said:
Hi,

Look at this:
Dim hc As TableHeaderCell
hc = New TableHeaderCell()
hc.BackColor = Drawing.Color.lightGray

My problem is:
i want to put the color into a variable like this:
dim mycolor as string
mycolor="red"
hc.BackColor = Drawing.Color.mycolor

But this doen't work because of the "".
Error: 'mycolor' is not a member of 'System.Drawing.Color'
Any way to do this?
Thanks
D.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top