Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have color saved in database like COLOR[RED]

how to apply this color to Label
like
Label1.Backcolor=
Posted
Updated 15-Apr-14 20:30pm
v2

Build a file mapper to convert COLOR[RED] to the respective color.
Ideally, tou can use an enum or map colors to the RGB values to store data.

This will make it easier for you to process this value when you fetch it from the database.
E.g.
lbl1.BackColor = MapToColor(COLOR[RED]);
 
Share this answer
 
Comments
hareshdgr8 16-Apr-14 1:58am    
it give me error what is MAPtoCOLOR please Explain or show me example

Please help me.
 
Share this answer
 
Comments
hareshdgr8 16-Apr-14 2:23am    
actually I have value like Color [RED] and need to apply this color on Label1.BackCOlor
if you have color names stored in database like 'RED', `GREEN` etc...

you can get Color object using System.Drawing.Color.FromName method

C#
Label1.Backcolor= System.Drawing.Color.FromName("GREEN");



update
----------

if you have stored colors like COLOR[RED]

VB
Dim fromDB As String = "COLOR[RED]"
Dim color As String = fromDB.Split( New Char(){"[", "]"})(1)
Label1.Backcolor = System.Drawing.Color.FromName(color)
 
Share this answer
 
v6
Comments
hareshdgr8 16-Apr-14 2:23am    
this code not working sorry..
DamithSL 16-Apr-14 2:25am    
can you update the question with the code how you read the color from database? I assume the color stored as RED, is it correct?
hareshdgr8 16-Apr-14 2:36am    
sir give me error please update .
hareshdgr8 16-Apr-14 2:37am    
error is type is expected

Dim fromDB As String = "COLOR[RED]"
Dim color As String = fromDB.Split(New () {"["C, "]"C})(1)
Label1.Backcolor = System.Drawing.Color.FromName(color)
DamithSL 16-Apr-14 2:42am    
Ok, pls check my updated answer
Dim str As String = COLOR [REd]
str=str.Replace("Color [", "")
str = str.Replace("]", "")
Dim c As Color = Color.FromName(str)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900