Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Buttons, RadioButton, CheckBox, etc > Change Radbutton Backcolor

Change Radbutton Backcolor

Feed from this thread
  • Posted on Aug 20, 2007 (permalink)

    Hi,
    I having difficuty to change the radbutton back color. I tried radbutton1.backcolor=color.red. This method is not working. Please help.
    thanks so much

    Reply

  • Dwight Dwight admin's avatar

    Posted on Aug 21, 2007 (permalink)

    Hi eriksurya,

    The background of the button is defined by the fill primitive. To change its properties, open the Edit UI Elements through the smart tag. It will open tree with the button control structure, select the FillPrimitive and configure it as you like. You can also use the Visual Style Builder to define button themes and save them in XML format.

     
    Best,
    Evtim
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Posted on Aug 21, 2007 (permalink)

    Hi,

    Can i change the color in running time? Using code especially. Thanks

    Reply

  • Kiril Kiril admin's avatar

    Posted on Aug 23, 2007 (permalink)

    Hello eriksurya,

    Thank you for contacting us with this question.

    You can change the back color of the RadButton at runtime using the following line of code:

    ((FillPrimitive)radButton1.ButtonElement.GetChildrenByType(typeof(FillPrimitive))[0]).BackColor = Color.Blue; 

    Please keep in mind that by default, the RadButton's fill mode is gradient, so if you need to have a solid background, you also need to add this next line of code. Using the GradientStyle property you can change the type of gradient (Gel, Glass, etc.)

    ((FillPrimitive)radButton1.ButtonElement.GetChildrenByType(typeof(FillPrimitive))[0]).GradientStyle = Telerik.WinControls.GradientStyles.Solid; 

    You have to use the BackColor2, BackColor3 and BackColor4 properties for the colors to be used for the gradient of the FillPrimitive. You can also modify the number of colors in the gradient using the NumberOfColors property of the FillPrimitive.

    Keep in mind, applying a BackColor like that will override any setting to the BackColor coming from a theme.

    Thank you for taking the time to write again. Please let me know if you have any additional questions.
     

    Greetings,
    Kiril
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Posted on Aug 24, 2007 (permalink)

    Hi,
    Thanks for your reply. Can telerik make this function easier, I mean the API? So we just lets say button1. backcolor1, button2.backcolor2, etc..
    thanks

    Reply

  • Kiril Kiril admin's avatar

    Posted on Aug 24, 2007 (permalink)

    Hello eriksurya,

    Thank you for your email. This is a request we get quite a bit. Simplifying the structure of our controls is important for a variety of reasons, but has to also be balanced with the flexibility the control has to offer.

    The decision to have the BackColors down at the level of the FillPrimitive was made for a variety of reasons:
    1. The BackColor property, together with other design properties is meant to be set using the Visual Style Builder, using a theme. It's not meant to be modified at runtime with user code.
    2. Having the BackColor property at the top-level of the Control would make the RadButton less customizable. For example, the user would have a single BackColor for the whole control, and will not be able to define a different BackColor for the text for example.
    3. Furthermore, the standard Microsoft button does not allow changing of the back color, and does not have such a property at all.
    If you have any additional comments, please share them with us. Thanks again for writing.
     

    Kind regards,
    Kiril
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Bryan Brannon avatar

    Posted on Nov 14, 2007 (permalink)

    Can you provide the VB.NET code to change the background color of a button using the FillPrimitive example above?

    Reply

  • Kiril Kiril admin's avatar

    Posted on Nov 15, 2007 (permalink)

    Hi Bryan Brannon,

    Thank you for writing.

    The FillPrimitive has a number of modes of operation. They are controlled by the GradientStyle and NumberOfColors properties. The FillPrimitive can use up to 4 colors (set using the BackColor, BackColor2, BackColor3 and BackColor4 properties) to be combined according to the GradientStyle and NumberOfColors properties to produce the final look.

    The code below uses the simplest scenario, with a solid fill with a single color set to red:

    DirectCast((Me.radButton1.GetChildAt(0).GetChildAt(0)), Telerik.WinControls.Primitives.FillPrimitive).GradientStyle = Telerik.WinControls.GradientStyles.Solid   
    DirectCast((Me.radButton1.GetChildAt(0).GetChildAt(0)), Telerik.WinControls.Primitives.FillPrimitive).NumberOfColors = 1   
    DirectCast((Me.radButton1.GetChildAt(0).GetChildAt(0)), Telerik.WinControls.Primitives.FillPrimitive).BackColor = System.Drawing.Color.FromArgb(CInt(CByte((240))), CInt(CByte((19))), CInt(CByte((44))))  

    I hope that helps. If you have any additional questions, please contact us again.

    Kind regards,
    Kiril
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

    Reply

  • Ryan avatar

    Posted on Jul 31, 2008 (permalink)

    The example of the DirectCast of the radbutton1 works...but when I tried it with a radtxtbox I got this error. Can you tell me why?

    System.InvalidCastException was unhandled
      Message="Unable to cast object of type 'Telerik.WinControls.UI.RadTextBoxItem' to type 'Telerik.WinControls.Primitives.FillPrimitive'."
      Source="PersonForm_072708"
      StackTrace:
           at PersonForm_072708.frmPerson.frmPerson_Load(Object sender, EventArgs e) in C:\projects\PersonForm_072708\PersonForm_072708\PersonForm_072708\frmPerson.vb:line 190
           at System.Windows.Forms.Form.OnLoad(EventArgs e)
           at Telerik.WinControls.UI.ShapedForm.OnLoad(EventArgs e)
           at System.Windows.Forms.Form.OnCreateControl()
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.Control.CreateControl()
           at System.Windows.Forms.Control.WmShowWindow(Message& m)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ContainerControl.WndProc(Message& m)
           at System.Windows.Forms.Form.WmShowWindow(Message& m)
           at System.Windows.Forms.Form.WndProc(Message& m)
           at Telerik.WinControls.UI.ShapedForm.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
           at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Control.Show()
           at PersonForm_072708.Form1.Button1_Click(Object sender, EventArgs e) in C:\projects\PersonForm_072708\PersonForm_072708\PersonForm_072708\Form1.vb:line 11
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnClick(EventArgs e)
           at System.Windows.Forms.Button.PerformClick()
           at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
           at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
           at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
           at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
           at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
           at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at PersonForm_072708.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()

    Reply

  • Peter Peter admin's avatar

    Posted on Aug 1, 2008 (permalink)

    Hello Ryan,

    This is a normal behavior because the RadButton and RadTextBox are different controls with different elements hierarchically - see the attached screenshots.

    You should use the Telerik SPY controls utility to inspect the elements hierarchy .

    Hope this will clear the situation.

    Greetings,
    Peter
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

  • John Davis Intermediate avatar

    Posted on Feb 18, 2011 (permalink)


    I am using a radform and radbuttons. It is important to change button colors. (If it is too hard, is there a different contral that would work better?)
    The code you provided works, but it changes only the top part, I guess because there is a gradient. (see the second button)
    How can I:
    1) Capture the button default background color definition (shown in the first button).
    2) In code, reset the button to this default background color definition, after it has been changed.
    2) In code, set the button background color so it looks like the third button (top and bottum have a new color).

    John
    Attached files

    Reply

  • Peter Peter admin's avatar

    Posted on Feb 23, 2011 (permalink)

    Hello John,

    Thank you for the writing.

    You should modify the BackColor and BackColor4 properties to change top and bottom colors - please refer to the attached project.

    In addition, you can create your own theme using our Visual Style Builder

    I hope this helps.

    All the best,
    Peter
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
    Attached files

    Reply

  • Robert avatar

    Posted on May 12, 2011 (permalink)

    i have created a theme that has modifed the radbutton and it work correctly.

    the button is simulating a generic hardware device used by our comapany.

    the theme is used 90% of the time as is, but somtimes i must change the color (fill)

    using the radbutton tasks to chage the fill color works for the idle state, but not for the mouse over, mousedown states.

    how can i edit those settings at runtime? using c# winforms

    thnaks

    (CNIN)


    Reply

  • Peter Peter admin's avatar

    Posted on May 17, 2011 (permalink)

    Hi Robert,

    You should modify the background color on MouseOver, MouseDown and MouseLeave events. I attached a sample project which demonstrates the described approach. Please take a look.

    Should you have any additional questions, do not hesitate to ask.

    Kind regards, Peter
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
    Attached files

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Buttons, RadioButton, CheckBox, etc > Change Radbutton Backcolor
Related resources for "Change Radbutton Backcolor"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]