BoldDesk®Customer service software with ticketing, live chat & omnichannel support, starting at $99/mo for unlimited agents. Try for free!
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
' Office2016Black
Me.sfButton.ThemeName = "Office2016Black"
|
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
Hi,
Have tested your sample and it works correct. This ticket can be close