Change Radbutton Backcolor

17 posts, 0 answers
  1. Erik
    Erik avatar
    80 posts
    Member since:
    Jul 2007

    Posted 20 Aug 2007 Link to this post

    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
  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 21 Aug 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Erik
    Erik avatar
    80 posts
    Member since:
    Jul 2007

    Posted 21 Aug 2007 Link to this post

    Hi,

    Can i change the color in running time? Using code especially. Thanks
  5. Kiril
    Admin
    Kiril avatar
    158 posts

    Posted 23 Aug 2007 Link to this post

    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
  6. Erik
    Erik avatar
    80 posts
    Member since:
    Jul 2007

    Posted 24 Aug 2007 Link to this post

    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
  7. Kiril
    Admin
    Kiril avatar
    158 posts

    Posted 24 Aug 2007 Link to this post

    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
  8. Bryan Brannon
    Bryan Brannon avatar
    65 posts
    Member since:
    Aug 2012

    Posted 14 Nov 2007 Link to this post

    Can you provide the VB.NET code to change the background color of a button using the FillPrimitive example above?
  9. Kiril
    Admin
    Kiril avatar
    158 posts

    Posted 15 Nov 2007 Link to this post

    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
  10. Ryan
    Ryan avatar
    25 posts
    Member since:
    Jul 2008

    Posted 31 Jul 2008 Link to this post

    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()
  11. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 01 Aug 2008 Link to this post

    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.
  12. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 18 Feb 2011 Link to this post


    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
  13. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 23 Feb 2011 Link to this post

    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!
  14. Chuck
    Chuck avatar
    9 posts
    Member since:
    Oct 2012

    Posted 12 May 2011 Link to this post

    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)


  15. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 17 May 2011 Link to this post

    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.
  16. Carol
    Carol avatar
    3 posts
    Member since:
    Dec 2011

    Posted 25 Jul 2013 Link to this post

    I placed a RadButton on my RadForm and changed the FillPrimitive back color settings to what I want.  I also changed the shape to the rounded rectangle and the radius to 15, so the button looks like it is rounded.  However, the corners still show the same color as the rounded part of the button.  I wish to set them to transparent so they are not visible, so the button actually looks rounded at runtime, and not square with a rounded line drawn inside of it.  How do I do this.  Every other backcolor property I found, anywhere, is set to transparent, but the corners still have color.  What am I missing?
  17. Carol
    Carol avatar
    3 posts
    Member since:
    Dec 2011

    Posted 25 Jul 2013 Link to this post

    Nevermind, I figured it out.  Discovered hidden code I had left behind where I was setting a theme at runtime.
  18. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 30 Jul 2013 Link to this post

    Hello Carol,

    I am happy that you found a solution for this.
    Please note that Edit UI Elements through the smart tag will serialize a local values and these values will override the theme settings.
    You can write back and open a new support ticket anytime you have further questions or need assistance.

    Regards,
    Peter
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready