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

Change ForeColor of radButton not working

8 Answers 452 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 08 Nov 2010, 02:32 PM
Hello,

Fairly simple need to change the fore color of a button, neither of the following lines change the color, how may I do this ?

cmdD1.ForeColor =

Color.White;

 

cmdD1.RootElement.ForeColor =

Color.White;

 


8 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 08 Nov 2010, 02:45 PM
Hello, 

To change the forecolor of a RadButton, you need to specify the ForeColor on the ButtonElement. 

Me.RadButton1.ButtonElement.ForeColor = Color.Blue

Hope that helps, but let me know if you need further help
Richard
0
Martin
Top achievements
Rank 1
answered on 08 Nov 2010, 06:24 PM
Thanks for response - but this simply doesnt appear to work. The Text ForeColor remains black regardless of how I try this. I'm even checking the InvokeRequired:

 

if (cmdNotImported.InvokeRequired)

 

cmdNotImported.BeginInvoke((

MethodInvoker)delegate

 

{

cmdNotImported.ButtonElement.ForeColor =

Color.White;

 

 

}

 

 

else

 

{

cmdNotImported.ButtonElement.ForeColor =

Color.White;

 

}

}



0
Richard Slade
Top achievements
Rank 2
answered on 08 Nov 2010, 06:27 PM
Hi Martin, 

That shouldn't be required. 
May I ask what version of the controls you are using? And where in the code you are trying to update the ForeColor of the button? 
Any other information will help me to resolve your issue. 

Thanks
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 08 Nov 2010, 06:29 PM
Also, can you confirm that you are not trying to update the ForeColor from a background thread. 
Thanks
Richard
0
Martin
Top achievements
Rank 1
answered on 08 Nov 2010, 06:52 PM
Hi, I'm using version 2010.2.10.806 of the controls which is 2010 Q2 SP1 I believe.

The ForeColor changes are done initially on the main GUI thread.

Subsequently a timer fires (running on a seperate thread), hence the InvokeRequired check, and those updates to the button are done on the Timer thread.

Neither seem to have any effect.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 08 Nov 2010, 07:36 PM
Hi,

Can you please try this very simple VB example in a new project. it's just two buttons on a form.
If this doesn't work for you, may I suggest upgrading to the latest 914 version (though the new Q3 version is out very soon)

let me know if that helps

Richard

Public Class Form1
  
    Private Delegate Sub ChangeColorHandler()
  
  
    Private Sub ChangeColor()
        If InvokeRequired Then
            Invoke(New ChangeColorHandler(AddressOf ChangebuttonColor))
        End If
    End Sub
  
    Private Sub ChangeButtonColor()
        Me.RadButton2.ButtonElement.ForeColor = Color.Green
    End Sub
  
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.RadButton1.ButtonElement.ForeColor = Color.Blue
  
        Dim myThread As New System.Threading.Thread(AddressOf ChangeColor)
        myThread.Start()
    End Sub
End Class
0
Accepted
Martin
Top achievements
Rank 1
answered on 09 Nov 2010, 10:46 AM
Richard, I have the Colors working now. I think I had a version mismatch between Q2 SP1 and SP2 that was probably throwing some first chance exceptions behind the scenes. Bringing all references to the right version and all seems to work fine now. Thanks
0
Richard Slade
Top achievements
Rank 2
answered on 09 Nov 2010, 10:51 AM
Glad you have this sorted Martin. If you feel that the post answered your question, please remember to mark as answer so others can find the solution too. 

All the best
Richard
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Martin
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Martin
Top achievements
Rank 1
Share this question
or