Hi Thanh,
Thank you for writing.
The
BackColor property is usually set through a
theme defining various colors for the different states.
TPF exposes an API for overriding the theme settings at run-time preserving the styles defined for all the element states:
Override Theme Settings at Run Time.
I created a simple example for toggling a color between two buttons inside
RadRibbonBar. Please check my code snippet below:
public
partial
class
Form1 : Form
{
private
Color initialColor;
public
Form1()
{
InitializeComponent();
this
.initialColor =
this
.radButtonElement1.BackColor;
this
.radButtonElement1.Click += radButtonElement1_Click;
this
.radButtonElement2.Click += radButtonElement2_Click;
}
private
void
radButtonElement1_Click(
object
sender, EventArgs e)
{
this
.ResetColor(
this
.radButtonElement2);
this
.ChangeBackColor(((RadButtonElement)sender));
}
private
void
radButtonElement2_Click(
object
sender, EventArgs e)
{
this
.ResetColor(
this
.radButtonElement1);
this
.ChangeBackColor(((RadButtonElement)sender));
}
private
void
ResetColor(RadButtonElement button)
{
if
(button.BackColor !=
this
.initialColor)
{
button.ResetThemeValueOverrides();
}
}
private
void
radButtonElement_Click(
object
sender, EventArgs e)
{
this
.ChangeBackColor(((RadButtonElement)sender));
}
private
void
ChangeBackColor(RadButtonElement button)
{
button.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty, Color.LightGreen,
""
,
typeof
(Telerik.WinControls.Primitives.FillPrimitive));
button.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.GradientStyleProperty, GradientStyles.Solid,
""
,
typeof
(Telerik.WinControls.Primitives.FillPrimitive));
}
}
I am also sending you a gif file showing the result on my end.
Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the
Telerik Feedback Portal and vote to affect the priority of the items