Change colors for all sfButton in a form

Hi,

I work on added themes to my app. Have written a subroutine that set style to black themes for the print tab, see code below. I want to change border, backcolor and forecolor for each sfButton in a form without hardcode each names of the SfButton.

Question:

How to change color for all sfButton controls in a form?


This example is not working.

        For Each ctl In frm.Controls

            If TypeName(ctl) = "Label" Then

                ctl.ForeColor = Color.White

            End If

        Next




    Public Sub SetTemaForm(ByVal frm As Form)

        Dim ctl As Control


        'sfButton

        With frm

            frmMain.BtnPrint2.Style.BackColor = Color.FromArgb(68, 68, 68)

            frmMain.BtnPrint2.Style.HoverBackColor = Color.FromArgb(102, 102, 102)

            frmMain.BtnPrint2.Style.Border = New Pen(Color.DarkGray, 1)

            frmMain.BtnPrint2.Style.ForeColor = Color.White

            frmMain.BtnPrint2.Style.HoverForeColor = Color.White


            frmMain.BtnPrinter.Style.BackColor = Color.FromArgb(68, 68, 68)

            frmMain.BtnPrinter.Style.HoverBackColor = Color.FromArgb(102, 102, 102)

            frmMain.BtnPrinter.Style.Border = New Pen(Color.DarkGray, 1)

            frmMain.BtnPrinter.Style.ForeColor = Color.White

            frmMain.BtnPrinter.Style.HoverForeColor = Color.White


            frmMain.BtnOrient.Style.BackColor = Color.FromArgb(68, 68, 68)

            frmMain.BtnOrient.Style.HoverBackColor = Color.FromArgb(102, 102, 102)

            frmMain.BtnOrient.Style.Border = New Pen(Color.DarkGray, 1)

            frmMain.BtnOrient.Style.ForeColor = Color.White

            frmMain.BtnOrient.Style.HoverForeColor = Color.White

        End With


        'label

        frmMain.Label8.ForeColor = Color.White

        frmMain.Label9.ForeColor = Color.White

        frmMain.Label10.ForeColor = Color.White

        frmMain.LblSettings.ForeColor = Color.White

    End Sub



5 Replies

TB Thirupathi Bala Krishnan Syncfusion Team January 7, 2022 02:59 PM UTC

Hi Thomas, 

The Syncfusion.Office2016Theme.WinForms assembly should be added as reference to set theme for the SfButton in any application. Before applying theme to the SfButton, required theme assembly should be loaded. We recommend adding the dll as an assembly reference and then loading the theme assembly by using the LoadAssembly method. There is no need to define the BackColor and ForeColor values as hard-coded if you are setting the theme name for SfButtons. 

' Office2016Black  
Me.sfButton.ThemeName = "Office2016Black" 


For more details, please refer to our UG documentation from the following link: 

The SfButton provides options for customizing the appearance based on the button state. BackColor, BorderColor, and ForeColor can all be customised with multiple states such as normal, hover, pressed, and disabled. 

For more details, please refer to our UG documentation from the following link: 

Could you please confirm that the theme you reported did not apply to the SfButton controls? Else It only applied if BackColor, BorderColor, and ForeColor were hard-coded values. We will provide a solution as soon as possible based on your updates. 

Regards,
Thirupathi B. 



TE Thomas Ellingsen January 7, 2022 03:52 PM UTC

There is nothing wrong with the Office2016 themes but I want to customizing appearance based on button state.


To awoid hardcode each sfButton and label in each backstage tab I write a routine that loops for all controls in a form and change forecolor for all labels and backcolor, forecolor and border for all sfButtons.


The function is need to find control backstage1 in the collection. It works first time it execute but after view the backstage and close it seems to missing the backstage control in collection.


Dim ctl as Controls

For each ctl in frm.controls

  Debug.Print(ctl.name)

next


Here is the code to set backstage tabs to Office2016Black without using themes. I have 15 controls in the form and first time the ctl collection is "BackStage1" but next time it execute the first item is "". So it can not change the colors.

How to fix or is it a bug?

How to get all controls in a backstage instead of a form?


    Private Sub SetTemaBlack(frm As Form)

        Dim ctl As Control 'Form

        Dim ctlsub As Control 'Backstage

        Dim ctlsub2 As Control 'BackstageTab


        'form

        For Each ctl In frm.Controls

            Debug.Print(ctl.Name)


            If TypeName(ctl) = "BackStage" Then


                'backstage

                For Each ctlsub In ctl.Controls


                    'backstageTab

                    For Each ctlsub2 In ctlsub.Controls


                        'label

                        If TypeOf ctlsub2 Is Label Then

                            ctlsub2.ForeColor = Color.White

                        End If


                        'sfButton

                        If TypeOf ctlsub2 Is SfButton Then

                            Dim sf As SfButton

                            sf = ctlsub2

                            sf.Style.BackColor = Color.FromArgb(68, 68, 68)

                            sf.Style.HoverBackColor = Color.FromArgb(102, 102, 102)

                            sf.Style.PressedBackColor = Color.FromArgb(128, 128, 128)

                            sf.Style.ForeColor = Color.White

                            sf.Style.HoverForeColor = Color.White

                            sf.Style.PressedForeColor = Color.White

                            sf.Style.Border = New Pen(Color.FromArgb(102, 102, 102), 1)

                            sf.Style.HoverBorder = New Pen(Color.FromArgb(128, 128, 128), 1)

                            sf.Style.PressedBorder = New Pen(Color.White, 2)

                        End If

                    Next

                Next

            End If

        Next


        ctl = Nothing

        ctlsub = Nothing

        ctlsub2 = Nothing

        frm = Nothing

    End Sub




TB Thirupathi Bala Krishnan Syncfusion Team January 11, 2022 06:15 AM UTC

Hi Thomas, 
 
We were unable to replicate the reported issue on our end. We tested the same reported scenario using your previous shared sample based on your code sample. Based on the value specified in the SetTemaBlack method, SfButton displayed as expected. Could you kindly check the issue with the following sample and update the feedback? Based on your updates, we’ll proceed further. 
 
Please refer to the attached videos and modified working sample from the following link. 
Regards, 
Thirupathi B. 



TE Thomas Ellingsen January 11, 2022 02:52 PM UTC

Hi,

Have tested your sample and it works correct. This ticket can be close



TB Thirupathi Bala Krishnan Syncfusion Team January 12, 2022 05:27 AM UTC

Hi Thomas, 

We are glad to know that the provided solution resolved your reported issue at your end. Please let us know if you need any further assistance on this. As always, we are happy to assist you. 

Regards, 
Thirupathi B. 


Loader.
Up arrow icon