2010-10-06 10 views

Respuesta

40

Usted podría intentar algo como:

Textbox1.BackColor = System.Drawing.ColorTranslator.FromHtml("#F2F0E1"); 
+0

Muchas gracias! Funciona ... –

+0

Funciona perfectamente Gracias. –

+0

Thankx, está funcionando –

0

Crear una función para obtener color de la cadena hexadecimal


public Color HexColor(String hex) 
    { 
    //remove the # at the front 
    hex = hex.Replace("#", ""); 

    byte a = 255; 
    byte r = 255; 
    byte g = 255; 
    byte b = 255; 

    int start = 0; 

    //handle ARGB strings (8 characters long) 
    if (hex.Length == 8) 
    { 
     a = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); 
     start = 2; 
    } 

    //convert RGB characters to bytes 
    r = byte.Parse(hex.Substring(start, 2), System.Globalization.NumberStyles.HexNumber); 
    g = byte.Parse(hex.Substring(start+2, 2), System.Globalization.NumberStyles.HexNumber); 
    b = byte.Parse(hex.Substring(start+4, 2), System.Globalization.NumberStyles.HexNumber); 

    return Color.FromArgb(a, r, g, b); 
    } 

continuación, establezca

Color c = HexColor("#F2F0E1"); 

Textbox1.BackColor = HexColor("#F2F0E1"); 

O

Textbox1.BackColor = c; 

referencia: http://silverlemma.blogspot.com/2009/03/c-converting-from-hex-string-to-color.html

2

hoja de estilo

.focusfld 
{ 
    background-color: #FFFFCC; 
} 


    .normalfld 
{ 
    background-color: #FFFFFF; 
} 

Javascript

function DoFocus(fld) 
{ 
    fld.className = 'focusfld'; 
} 
function DoBlur(fld) 
{ 
    fld.className='normalfld'; 
} 

Código detrás

TempTextBox.Attributes.Add("onFocus", "DoFocus(this);"); 
    TempTextBox.Attributes.Add("onBlur", "DoBlur(this);"); 
Cuestiones relacionadas