How to pass color code to a sub-routine

Peter Hibbs 101 Reputation points
2021-02-21T15:01:20.593+00:00

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.

Developer technologies | Windows Forms
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,686 Reputation points
    2021-02-21T15:26:58.403+00:00

    You can just do :

    Private Sub SetBkColor(ctrl As Control, col As Color)
        ctrl.BackColor = col
    End Sub
    

    call :

     SetBkColor(TextBox1, Color.Red)
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Peter Hibbs 101 Reputation points
    2021-02-21T16:15:36.937+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.