Identifying buttons on a form

0
0

Hi there,

I am currently developing an application based on a legacy website currently in use.

I wish to standardize our the application by having button backgrounds set to a a certain color based on their function. I am intending to do this by standardizing button names based on their function, e.g. Adding = “ButtonAdd”, Closing = “ButtonClose”. I call a function in the form_load event passing the current form as a parameter in order to set various things within the form, all of which currently work correctly apart from the buttons.

I have been attempting to loop through the controls on a form, and where the control type is a button, change the color based on it’s name. The code I have used for this is reproduced below:

Module ModFormFunctions

Public Sub FormSetup(ByVal Frm As Form)
‘Set form header
Frm.Text = gblConfig.Council & ” ” & gblConfig.CouncilType & “: ” & Frm.Text
‘Set form background colour
Frm.BackColor = gblDatabase.BG
‘Loop through controls on form
For Each Ctrl As Control In Frm.Controls
‘Check if a button
If TypeOf Ctrl Is Button Then
‘Check name and set color as appropriate
Select Case Ctrl.Name
Case Is = “ButtonAdd”
Ctrl.BackColor = gblAddColor
Case Is = “ButtonClose”
Ctrl.BackColor = gblCloseColor
Case Is = “ButtonDelete”
Ctrl.BackColor = gblDeleteColor
Case Is = “ButtonEdit”
Ctrl.BackColor = gblEditColor
Case Is = “ButtonNoSave”
Ctrl.BackColor = gblNoSaveColor
Case Is = “ButtonSave”
Ctrl.BackColor = gblSaveColor
Case Else
Ctrl.BackColor = gblMiscColor
End Select
End If
Next
End Sub
End Module

I call this function using FormSetup(Me)..

I have debugged the function and it can’t find any controls. Any ideas?

Thanks
Gareth Bond

  • You must to post comments
0
0

Hi Gareth,

I quickly checked this and could not reproduce.
Do you have an Imports Wisej.Web in your Code ?

What´s TypeOf Ctrl in your code when you debug it ?

Best regards
Frank

  • Frank (ITG)
    Or are your buttons maybe in a container like a Panel or a GroupBox ? Regards Frank.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.