locked
Applying colours dynamically RRS feed

  • Question

  • User-1214797176 posted

     hi friends,

    In my application i want to pick up colors from colour picker, like if i select color from color picker against label, then all the labels in the application should get that colour.

    please tell me how can i do this?

    Thanks in advance.

    Tuesday, June 2, 2009 7:09 AM

Answers

  • User-1934860317 posted

    you can run a loop on all label controls somehting like this

    Public Shared Sub ResetFormValues(ByVal parent As Control)

    For Each c As Control In parent.Controls

    If c.Controls.Count > 0 Then

    ResetFormValues(c)

    Else

    Select Case (c.GetType().ToString)

    Case "system.Web.UI.WebControls.Label"

    CType(c, Label).ForeColor = Drawing.Color.Maroon

    Exit Select

    End Select

    End If

    Next

    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2009 10:39 AM

All replies

  • User-925286913 posted

    If you want to do it in javascript then:

    var Label1 = document.getElementById("<%=Label1.ClientID%>");
               
    Label1.style.color = document.getElementById('txtColor').value;

    Code-Behind:

    Label.ForeColor = txtColor.Text

    Tuesday, June 2, 2009 8:34 AM
  • User-1214797176 posted

     Hi frds,

    Thank you very much for your replies. I have gone through these links.

     My requirement is if i select label back color to maroon , all labels should display in maroon color in entire application.

     

    Tuesday, June 2, 2009 10:16 AM
  • User-1934860317 posted

    you can run a loop on all label controls somehting like this

    Public Shared Sub ResetFormValues(ByVal parent As Control)

    For Each c As Control In parent.Controls

    If c.Controls.Count > 0 Then

    ResetFormValues(c)

    Else

    Select Case (c.GetType().ToString)

    Case "system.Web.UI.WebControls.Label"

    CType(c, Label).ForeColor = Drawing.Color.Maroon

    Exit Select

    End Select

    End If

    Next

    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 2, 2009 10:39 AM
  • User-925286913 posted

    Do you want to change it permanently or just for one time?

    Secondly, Do you want to do it with javascript or code-behind?

    Tuesday, June 2, 2009 12:49 PM
  • User-1214797176 posted

     hi

    could you please tell me "ResetFromValues " method from where i need to call?

    if possible please send me c# code....(dont mind if i am asking too much).

    if a user changes colors and back ground  it should appear only to him. Just like iGoogle.

    User can set his own custom settings. it can be javascript or c#.

     

     

    Wednesday, June 3, 2009 12:15 AM
  • User-1934860317 posted

    private void ResetFormValues(Control parent, selectedColor String)
        {
            foreach (Control c in parent.Controls)
            {
                if (c.Controls.Count > 0)
                {
                    ResetFormValues(c);
                }
                else
                {
                    switch(c.GetType().ToString())
                    {
                        case "System.Web.UI.WebControls.Label":
                            ((Label)c).ForeColor =  selectedColor; 

                            break;    
                    }             
                }
            }
        }

     

    You can call this function when user change the color of one Label as you see i put another parameter as selectedColor so when

    user change color of a label call this function and pass the color parameter it will change all the label colors....

    Wednesday, June 3, 2009 1:51 AM
  • User-1214797176 posted

     Thnk you very much. It helped me.

    Wednesday, June 3, 2009 2:18 AM