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

ForeColor not used?

15 Answers 276 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 28 Mar 2008, 05:42 PM
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

15 Answers, 1 is accepted

Sort by
0
Kiril
Telerik team
answered on 31 Mar 2008, 11:50 AM
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
0
ManniAT
Top achievements
Rank 2
answered on 31 Mar 2008, 02:49 PM
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
0
Accepted
Kiril
Telerik team
answered on 31 Mar 2008, 03:34 PM
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
0
ManniAT
Top achievements
Rank 2
answered on 31 Mar 2008, 04:04 PM
Thanks a lot - perfect support - as usual :)
0
Ryan
Top achievements
Rank 1
answered on 18 Nov 2008, 02:41 PM
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
0
Ryan
Top achievements
Rank 1
answered on 18 Nov 2008, 03:47 PM

 

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
0
Nick
Telerik team
answered on 19 Nov 2008, 07:02 PM
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.
0
Hassan
Top achievements
Rank 1
answered on 21 Jan 2009, 04:59 AM
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

0
Hassan
Top achievements
Rank 1
answered on 21 Jan 2009, 08:36 AM
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

 

 

 

 

 

 

 

 

0
Nick
Telerik team
answered on 22 Jan 2009, 08:48 AM
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.
0
Dennijr
Top achievements
Rank 1
answered on 12 Oct 2009, 10:15 AM
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...
0
Nick
Telerik team
answered on 12 Oct 2009, 10:38 AM
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.
0
Dennijr
Top achievements
Rank 1
answered on 12 Oct 2009, 11:10 AM
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
0
Nick
Telerik team
answered on 12 Oct 2009, 11:26 AM
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.
0
Dennijr
Top achievements
Rank 1
answered on 12 Oct 2009, 06:18 PM
works perfectly, thank you good sir!
Tags
General Discussions
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Kiril
Telerik team
ManniAT
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Nick
Telerik team
Hassan
Top achievements
Rank 1
Dennijr
Top achievements
Rank 1
Share this question
or