You can just do :
Private Sub SetBkColor(ctrl As Control, col As Color)
ctrl.BackColor = col
End Sub
call :
SetBkColor(TextBox1, Color.Red)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am using VS 2019 (Visual Basic.Net). How can I pass a color value to a sub-routine.
I have a form with a Text box (several in fact) and I want to call a sub-routine and pass a color code to the sub-routine which would then change the BackColor of the Text box control. What would the form code look like and what would the sub-routine code look like?
Note that this is my first attempt at programming in VB.Net although I have been programming in VBA using MS Access for over 20 years.
Peter Hibbs.
You can just do :
Private Sub SetBkColor(ctrl As Control, col As Color)
ctrl.BackColor = col
End Sub
call :
SetBkColor(TextBox1, Color.Red)
Hi Castorix31,
OK, thanks, that works a treat (actually a lot easier than I thought it was going to be and it also solves my next question about how to pass the Text box control ref to the sub-routine).
Peter.