Open your first program (called vb1) if it is not open already.

Adding More Buttons

Add 2 more buttons to your form. 

Double Click on cmdBlue to open the code window (or click on cmdBlue then press F7).  Fill in the line of code in bold from below:

Private Sub cmdBlue_Click()
      frmMain.BackColor = vbBlue
End Sub

Close the code window and test your program

Show Me How

Repeat for the Green button, but use vbGreen for the colour.

You can use the following words for colours in Visual Basic:

vbRed, vbGreen, vbBlue, vbWhite, vbBlack, vbCyan, vbYellow, vbMagenta

If you want colours other than those, you need to use RGB values.

RGB stands for Red, Green, Blue.  The values can range from 0 to 255 - the first number is for Red, the second is for Green and the third is for Blue. 

So RGB(255, 0, 128) has a lot of red, no green and a medium amount of blue, making a purple colour.

You need to write your code in this format:

frmMain.BackColor = RGB(255,0, 128)

 

Start a new project.  Name your form and give it a caption.

Write a new program that has a button that makes the form wider and another that makes the form narrower. (Not a very exciting program yet, but you've got to start somewhere!)

If your form is named frmMain, the line of code you will need to make it 3000 twips wide is:

frmMain.width = 3000