This is a migrated thread and some comments may be shown as answers.

RadToggleButton Backgrounds

1 Answer 143 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 22 Oct 2008, 03:00 PM
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

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 27 Oct 2008, 01:09 PM
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.
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
David
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or