VB6 Tutorial 09: Common Properties 1 of 3

Posted On 2018-03-24 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner,common,properties,part1
Tags: VB6 Tutorials Windows
Views: 63

Title Uploaded Size
Common_Properties.zip 4/1/2018 9:51:33 AM 1,267


Looking for the more of the VB6 Tutorial? Here is the tutorial index.

Common properties are properties that are shared by most objects in the VB6 Toolbox. Some have more, while others have fewer. In this section we'll start looking at four of them.

The BackColor and ForeColor properties

The BackColor property sets the background color of an object while the ForeColor property changes the foreground color used to display text.

You can set these properties either from Properties Window or you may wish to set in run-time.

Example

When you click on command1 button, the code in the Click event procedure is executed.

Private Sub cmdChangeColor_Click()
    Label1.BackColor = vbRed
    Label1.ForeColor = vbBlue
End Sub

On execution, the background color of the label will be red and labels text color will be blue.

vbRed and vbBlue are the color constants.

Here is another example :

Private Sub cmdChangeColor_Click()                   
    Label1.BackColor = vbRed                       
    Label1.ForeColor = vbBlue                      
    Form1.BackColor = vbGreen                      
    Text1.BackColor = vbBlack                      
    Text1.ForeColor = vbYellow                     
    Frame1.BackColor = vbWhite                     
End Sub

The color can also be expressed in hexadecimal code.

Example

Private Sub cmdChangeColor_Click()
    Label1.BackColor = &HFF&
    Label1.ForeColor = &HC00000
End Sub

In this case, you have to copy the hexadecimal code from Properties Window.

The Font Property

You can set the font properties from the Properties Window. See the below example to set property in run time.

Example

Private Sub cmdChangeFont_Click()
    Text1.FontSize = 16
    Text1.FontBold = True
    Text1.FontItalic = True
    Text1.Font = "Tahoma"
End Sub

The above block of code can be written in the following way as well:

Private Sub cmdChangeFont_Click()
    Text1.Font.Size = 16
    Text1.Font.Bold = True
    Text1.Font.Italic = True
    Text1.Font.Name = "Tahoma"
End Sub

QuickHint:

Don't forget to turn intellisense on in the IDE, if you haven't already. Intellisense gives you the ability to type the first one or two characters of a property, then pop up a list for you to finish it from.

The Caption property

It sets the text displayed in the objects title bar or on the object.

Example

Private Sub cmdSetTitle_Click()
    Form1.Caption = "New Program"
    Label1.Caption = "Hello"
    Frame1.Caption = "New frame"
End Sub

The Caption property of form sets the forms title text. The text to be displayed on label is set.

The Text property

It sets the text in a TextBox.

Example

Text1.Text = "New program" 

Here the text string is assigned to Text1.Text

That's it for the first section of common properties. In the next section, we'll cover a nine more:

  • Left
  • Top
  • Width
  • Height
  • Container
  • Visible
  • Enabled
  • MousePointer
  • MouseIcon

Looking for the more of the VB6 Tutorial? Here is the tutorial index.


About the Author

VB6Boy has posted a total of 71 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:23.20.165.182

Before you can post, you need to prove you are human. If you log in, this test goes away.




Code Links