RadToggleButton Backgrounds

2 posts, 0 answers
  1. David
    David avatar
    14 posts
    Member since:
    Jul 2008

    Posted 22 Oct 2008 Link to this post

    Hi:

    I'm creating a list of RadToggleButtons on runtime dinamically, an then I add some events to change their appeareance:

     

    private void bottonDevice_MouseEnter(object sender, EventArgs e)

     

    {

     

    RadToggleButton button = (RadToggleButton)sender;

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(251)))), ((int)(((byte)(206)))), ((int)(((byte)(117)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor3 = System.Drawing.Color.FromArgb(((int)(((byte)(249)))), ((int)(((byte)(196)))), ((int)(((byte)(52)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor4 = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(220)))), ((int)(((byte)(158)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(232)))), ((int)(((byte)(180)))));

     

    }


    The Event MouseEnter changes the Togglebutton background successfully, so the MouseLeave Event too. But the ToggleStateChanged Event simply doesn't work :( here's the Event code.

     

     

    private

     

    void buttonDevice_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)

     

    {

     

    // ToggleChange(btnView);

     

     

     

     

     

    RadToggleButton button = (RadToggleButton)sender;

     

    ToggleChange(button);

     

    if (args.ToggleState == ToggleState.On)

     

    {

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(254)))), ((int)(((byte)(167)))), ((int)(((byte)(77)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor3 = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(146)))), ((int)(((byte)(0)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor4 = System.Drawing.Color.FromArgb(((int)(((byte)(253)))), ((int)(((byte)(204)))), ((int)(((byte)(116)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(254)))), ((int)(((byte)(197)))), ((int)(((byte)(136)))));

     

     

     

     

    }

     

    else

     

     

     

     

    {

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(193)))), ((int)(((byte)(193)))), ((int)(((byte)(193)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor3 = System.Drawing.Color.FromArgb(((int)(((byte)(151)))), ((int)(((byte)(148)))), ((int)(((byte)(148)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor4 = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));

     

    ((Telerik.WinControls.Primitives.

    FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(226)))), ((int)(((byte)(226)))), ((int)(((byte)(226)))));

     

     

     

     

    }

    }

    Can you help me with that issue?. I write my code that way because, I've tried to apply a Theme loaded in design time to my controls, but it didn't work either.

    Thanks
  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 27 Oct 2008 Link to this post

    Hello David,

    Thank you for contacting us. We are as always eager to help you.

    First off, I would like to apologize in case I have not understood your issue completely.

    I have changed your sample code's colors to check things - the backgroud color on mouse enter is changed to green and on mouse leaves to a different green. When ToggleStateChanged is invoked the color is set to Red/Yellow. You can find my code below.

    I am not sure, however, why ToggleStateChanged is not working and what ToggleChange(button) is doing (I have commented these lines to run your code). ToggleStateChanged event is fired only when the state is changed, which is when the mouse is clicked, or the enter button is pressed when the button has focus. When you leave the button the the background color is changed to the color specified in MouseLeave event.

     private void radToggleButton1_ToggleStateChanged(object sender, StateChangedEventArgs args)  
            {  
                // ToggleChange(btnView);   
                RadToggleButton button = (RadToggleButton)sender;  
                //ToggleChange(button);  
     
                if (args.ToggleState == ToggleState.On)  
                {  
     
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor2 = System.Drawing.Color.Red;  
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor3 = System.Drawing.Color.Red;  
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor4 = System.Drawing.Color.Red;  
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor = System.Drawing.Color.Red;  
                }  
                else 
                {  
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor2 = System.Drawing.Color.Yellow;  
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor3 = System.Drawing.Color.Yellow;  
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor4 = System.Drawing.Color.Yellow;  
                    ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor = System.Drawing.Color.Yellow;  
                }  
     
            }  
     
            private void radToggleButton1_MouseEnter(object sender, EventArgs e)  
            {  
                RadToggleButton button = (RadToggleButton)sender;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor2 = System.Drawing.Color.Green;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor3 = System.Drawing.Color.Green;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor4 = System.Drawing.Color.Green;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor = System.Drawing.Color.Green;  
            }  
     
            private void radToggleButton1_MouseLeave(object sender, EventArgs e)  
            {  
                RadToggleButton button = (RadToggleButton)sender;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor2 = System.Drawing.Color.Green;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor3 = System.Drawing.Color.GreenYellow;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor4 = System.Drawing.Color.GreenYellow;  
                ((Telerik.WinControls.Primitives.FillPrimitive)(button.GetChildAt(0).GetChildAt(0))).BackColor = System.Drawing.Color.GreenYellow;  
            }  
     

    Please tell me what is your scenario to help you further. Also do not hesitate to contact me if you have more questions.
     

    Greetings,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top