ForeColor not used?

16 posts, 1 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 28 Mar 2008 Link to this post

    Hi,

    I use a rad button.
    All I want to do is to change the ForeColor depending on the situation.

    Trying this I found - nothing happens.
    So I tried in designer - also the same result.

    Whatever I set for forecolor is ignored.

    I do nothing more than a clean project - drag a button to it and try to change forecolor.

    The button is nice blue (like menus) and the textcolor is darkblue - not changeable.

    Regards

    Manfred
  2. Kiril
    Admin
    Kiril avatar
    158 posts

    Posted 31 Mar 2008 Link to this post

    Hello Manfred Pohler,

    Thank you for writing.

    You are correct, ForeColor is not taken into consideration when setting the ForeColor when a Theme is used. This follows the Microsoft convention for behavior of basic properties in complex controls. For example, the ForeColor property of the Micrisoft TabControl is hidden.

    In our controls, you can still change the value of the ForeColor, but it only applies when there is no theme applied. You can have a situation where no Theme is set by setting the ThemeName property to a non-existent theme name, such as "notheme". Once there's no theme applied, the ForeColor property you have set from the control will be applied.

    You can still achieve an appearance that is a combination of theme values and values that you have provided:

    1. Use the UI Elements Editor, which you can launch using the smart tag at design-time. Once the dialog shows, you'll see a tree on the left, indicating the structure, and a property grid on the right, where you can set property values for the element selected in the tree on the left. In your particular case, select the TextPrimitive in the tree on the left, and set its ForeColor property in the property grid.

    2. Create a theme using the Visual Style Builder. Open the VSB, load the RadButton, select the TextPrimitive from the tree in the left dock window, and change its ForeColor property in the right dock window. You can then save the theme, and load it at designtime.

    I hope this helps. If you have any further questions, please contact me.

    Regards,
    Kiril
    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. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 31 Mar 2008 Link to this post

    Hi,

    thanks for your answer - it DESCRIBES the "problem" - but how can I change the forecolor of the text if using a theme?

    My approach is very simple:
    This is some kind of a login button.
    If no user is logged in it displays ??? - in "default color".
    I a "normal" user is logged in it displays it's name in "Green".
    If an administrative user is logged in it displays in red and bold.

    So how to access "bold" and color?

    Regards

    Manfred
  5. Answer
    Kiril
    Admin
    Kiril avatar
    158 posts

    Posted 31 Mar 2008 Link to this post

    Hello Manfred Pohler,

    I now understand an important detail of your scenario, namely that you want to make this change in font and color at runtime. In my previous email to you, I listed the possible solutions at design-time.

    You can achieve the appearance you desire by changing the property values for the TextPrimitive (the object responsible for drawing text) at runtime. I'm sending you a small code block to illustrate the approach.

    Place two RadButtons in a form. Paste the code below in the event handler for the Click event for the second button:

            private void radButton2_Click(object sender, EventArgs e)  
            {  
                if (!((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).ForeColor.Equals(Color.Red))  
                {  
                    ((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).ForeColor = Color.Red;  
                    ((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).Font = new Font(((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).Font, FontStyle.Bold);  
                }  
                else 
                {  
                    ((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).ForeColor = Color.Green;  
                    ((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).Font = new Font(((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).Font, FontStyle.Regular);  
                }  
            } 

    I hope this helps resolve the issue. If you have any further issues, let me know.

    Regards,
    Kiril
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 31 Mar 2008 Link to this post

    Thanks a lot - perfect support - as usual :)
  7. Ryan
    Ryan avatar
    25 posts
    Member since:
    Jul 2008

    Posted 18 Nov 2008 Link to this post

    Would support please submit the VB version of the above code sample?

    Also...how do i access the forecolor of a radtextbox, radcombobox, and radmaskedtextbox at runtime?

    Thanks
  8. Ryan
    Ryan avatar
    25 posts
    Member since:
    Jul 2008

    Posted 18 Nov 2008 Link to this post

     

    Would support please submit the VB version of the above code sample?

    Also...how do i access the forecolor of a radtextbox, radcombobox, and radmaskedtextbox at runtime?

    Thanks
  9. Nick
    Admin
    Nick avatar
    767 posts

    Posted 19 Nov 2008 Link to this post

    Hi Ryan,

    Thank you for your questions.

    Please use the following tool for translating the code.

    You have to access the RootElement of the given control (or alternatively the element which shortcuts the first child) and then access it children. If you need to see the children hierarchy do the following: drag a control on the form, open its smart tag (in the upper right corner of the control), choose Open Theme Builder, and you can see the children on the right (the tree structure). Take for example the TextPrimitive (a child in the hierarchy) of RadButton in the code below. For more information on primitives, please refer to our help --> architecture.

    Sincerely yours,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Hassan
    Hassan avatar
    15 posts
    Member since:
    Jan 2009

    Posted 20 Jan 2009 Link to this post

    Hi,

    I also have the same issue and followed the thread, the code you provided for the C# (for fore color of the button) is

    ((TextPrimitive)radButton1.RootElement.Children[0].Children[1].Children[1]).ForeColor = Color.Red;  

    is converted to vb code on the link you provided in previous post to

    (DirectCast(radButton1.RootElement.Children(0).Children(1).Children(1), TextPrimitive)).ForeColor = Color.Red

    which gives me "Syntax error"

    Could you please correct me in the above line.

    Also when I used as you instructed i am unable to find forecolor property in specific children e.g.

    btn1.RootElement.Children(0).Children(1).Children(1).forecolor


    As in the hierarchy found in theme builder it is correct but not working

    Could you give me the exact vb code line that i can use.

    Thanks and regards,

    Hassan

  11. Hassan
    Hassan avatar
    15 posts
    Member since:
    Jan 2009

    Posted 21 Jan 2009 Link to this post

    Hi,

    I found the solution by adding the following code for vb which does the trick

     

    Imports Telerik.WinControls.Primitives

    DirectCast (Ps_Button.RootElement.Children(0).Children(1).Children(1), TextPrimitive).ForeColor = Color.Black

    Thanks and regards

    Hassan

     

     

     

     

     

     

     

     

  12. Nick
    Admin
    Nick avatar
    767 posts

    Posted 22 Jan 2009 Link to this post

    Hi Hassan,

    Thank you for your inquiry. The VB converter added a pair of redundant brackets. Here is the correct code:

    Imports Telerik.WinControls.Primitives 
     ...
    Public Class Form1 
     ...
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
            DirectCast(RadButton1.RootElement.Children(0).Children(1).Children(1), TextPrimitive).ForeColor = Color.Red 
        End Sub 
    End Class 

    Do not hesitate to write me back if you have more questions.

    Kind regards,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Dennijr
    Dennijr avatar
    4 posts
    Member since:
    Sep 2009

    Posted 12 Oct 2009 Link to this post

    i am trying to change the fill colour of a button, i figured it would probably be the same, so i tried;

    DirectCast(RadDropDownButton4.RootElement.Children(0).Children(1).Children(1), Telerik.WinControls.Primitives.FillPrimitive).BackColor = Color.Red

    (with vb.net)

    but no such luck...
  14. Nick
    Admin
    Nick avatar
    767 posts

    Posted 12 Oct 2009 Link to this post

    Hello Dennijr,

    Thank you for contacting us. You need not change the color with code in most cases -- you can simply use the Edit UI Elements dialog. If you need code, you can see the tree of elements in this dialog and then access the correct child with code. In this case, you are looking for the FillPrimitive of the button control and you have to access first the 0th child to access the ButtonElement and then the 0th child of this element to access the FillPrimitive. I hope that this helps. Do not hesitate to write me back if you have further questions.

    Best wishes,
    Nick
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  15. Dennijr
    Dennijr avatar
    4 posts
    Member since:
    Sep 2009

    Posted 12 Oct 2009 Link to this post

    i found where i need to be, i think, i can change the colours manually, i just cant do it with code, i am using the dropdown buttons, i forgot to specify =S
    i think that going to 'children(0).children(0)' would be going into the border colour property
    from what i understand, the code from my first post should work, but i must be missing something... thanks for the replys btw =)

    Imports Telerik.WinControls.Primitives 
     ...
    Public Class Form1 
     ...
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
            DirectCast(RadDropDownButton4.RootElement.Children(0).Children(1).Children(1), FillPrimitive).BackColor = Color.Red 
        End Sub 
    End Class 

    this is what i am using now, but its not working... however, my code is not within the form_load
  16. Nick
    Admin
    Nick avatar
    767 posts

    Posted 12 Oct 2009 Link to this post

    Hello Dennijr,

    Thank you for contacting us back. If you want to access the correct FillPrimitive of RadDropDownButton, you have to additionally access the 0th child of the element you are currently accessing.

    DirectCast(Me.radDropDownButton1.DropDownButtonElement.Children(1).Children(1).Children(0), FillPrimitive).BackColor = Color.Yellow

    Do not hesitate to write me back if you have further questions.

    Greetings,
    Nick
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  17. Dennijr
    Dennijr avatar
    4 posts
    Member since:
    Sep 2009

    Posted 12 Oct 2009 Link to this post

    works perfectly, thank you good sir!
Back to Top
UI for WinForms is Visual Studio 2017 Ready