Object on Microsoft Visual Studio


Objects on Visual Basic
What is meant by Object

Object is a combination of code and data that can be treated as a single unit . An object can be a part of the application such as a control or a form . Whole of the application can also be an object .

Where does it come Objects
Each object in Visual Basic is defined by a class . To understand the relationship between objects with his class , consider the following example :

· The controls that gentleness on the Toolbox window in Visual Basic is classes . The object is known as the control will not exist until you plant them in a form . When you embed a control , you have to make a duplication or an instance of the control class .

· Form where you work at design time is a class . At run time , Visual Basic creates an instance of the class form .

Suppose you menamkan a textbox on form1 , consider the control properties window will display Text1 ( the name of the textbox control ) and Textbox ( the name of the control class ) .

All objects are duplicated from their class . Shortly after becoming a stand-alone objects , each of which can have different properties .

Suppose you plant three command button on a form , each command button is an instance of the class CommandButton so have a number of characteristics and capabilities ( properties , methods , and events ) are the same , which is defined in the class - her . However , each can have a Name , Caption , BackColor , different style according to the settings on each property .

Working with objects
Visual Basic objects have properties , methods , and events . In Visual Basic , an object data ( settings and attributes ) is referred to as property , while a variety of subroutines that can operate on the object referred to as methods. And an action event is recognized by an object , such as mouse clicks or keystrokes , so you can write code to handle the event.

Set the property value
You can directly set the property value of a control in the properties window , or at runtime by using the following forms of writing :

Objek.properti = expression

or

Private Sub Form_Load ( ) MyForm.Caption = " User Phone " End Sub
Taking the value of the property
You can take the value of the property of an object with writing as follows :

Variable = Objek.properti

example :

Private Sub cmdProses_Click ( ) Name = txtNama.Text End Sub
Using the method in the Code
When you use a method in your code , it depends on how the terms of the order and how many arguments are needed , and whether the method returns a value . When a method takes no arguments you can write it as follows ::

Objek.Metode

example :

Private Sub cmdBuka_Click ( ) End Sub frmPemakai.show
Some of the common property
The following will discuss some general properties are almost present in all intrinsic controls in Visual Basic .

Properties Left , Top, Width and Height

All visible objects have properties that determine the location and size. Left and Top property value is relative to the container ( eg an embedded textbox on the form , then the form is referred to as a container for the textbox ) , while the Width and Height define the size of the object .

Nb . At the default value of this property is expressed in twips ( 1 inch = 1440 twips ; 1 centimeter = 576 twips )

Attention : Width and Height Properties in nature readonly Combobox control .

ForeColor and BackColor properties

Generally visible object has ForeColor and Backcolor properties , which affect the text color and background color , but some of them do not exist ( for example, control the scroll- bars) , in the command button there is no ForeColor property , and Backcolornya only works if you change their style property to 1 - Graphical .

Nb . Setting Backcolor property became not work if you set the property BackStyle be 0 - transparent .





When you specify a value for this property , you can use a standard color , or custom colors ( I recommend you to use a standard color to keep the wearer a sense of the value of integration with the operating system )

Font property

At design time , you can specify the font properties dialog box , but at runtime , it should be done with the property Name , Size , Bold , Italic , Underline , and strikethrough , because the actual Font object is a mixture .

example :

Text1.Font.Name = " Tahoma " Text1.Font.Size = 12 Text1.Font.Underline Text1.Font.Bold = True = True
Caption and Text properties

Caption is the text that appears in a control ( or title on the object form ) in which the user can not modify directly ( control Label , CommandButton , Checkbox , OptionButton , Data , and Frame ) , instead Text is the text that can be modified by the user ( control textbox, Listbox and Combobox ) .

Nb . In the Caption property , we can use the & ( ampersand ) to declare the hotkey for control . Text properties can be ignored , as it is the default property for a control .

example :

' Both of these commands are the same Text2.Text = Text1.Text = Text1 Text2 ' property without text
Enabled and Visible properties

At default all controls and forms are Enabled and Visible . You can hide a control by using the Visible property = False . Control Enabled = False property can not be accessed by the user , but can be accessed in code .

Programmers can also use the Locked property = True to create a read-only control .

Tabstop property and the TabIndex

A control that can receive the input focus has the tabstop property . Control has tabstop property also has a TabIndex property . Tabstop property to determine whether a control can receive focus on Tab keystrokes by the user , the default is true , while the TabIndex property determines the order of focus when the user presses the Tab .

MousePointer property and MouseIcon

This property will determine the shape of the cursor when the mouse is over the control . Windows allow us to set the mouse to display each form and control by following these rules :

If the property Screen.MousePointer set to values ​​that are not 0 - vbDefault , the mouse cursor will follow this value , but when the mouse is hovering over another application ( or on the desktop ) , the cursor display will depend on the conditions of the relevant application , not on your application .
If Screen.MousePointer is 0 and the mouse cursor is over a control , Visual Basic will check the value of the property MousePointer control ; when its value is not 0 - vbDefault , the mouse cursor will be set to that value .
If Screen.MousePointer is 0 and the mouse is hovering over the surface of a form or control over the property is MousePointer is 0 , Visual Basic will use the value stored in the property Mousepointer on the form .
MouseIcon property can be used to display the mouse pointer shape in accordance with the wishes of the user , but before MouseIcon property should be set to 99 - vbCustom , and then set an icon on the property MouseIcon .





property Tag

All controls support the Tag property , without exception , because the property is provided by Visual Basic , not by control . Tag property is used as a container for the data from the control that you want to save ( for example, you can use it to store the initial value of the textbox , so the user can perform Undo to restore the initial value of the Tag property ) .

Some common methods
The following will discuss some of the most common methods found in all intrinsic controls in Visual Basic .

methods Move

If a control supports properties Left , Top, Width , and Height , also supports the Move method , with which you can convert some or all of the properties in one single operation . The following example turns three properties : Left , Top , and Width .

example :

' Mendoublekan width form , and move to the upper left corner of the screen ' syntax is : Move Left , Top, Width , Height . Form1.Move 0 , 0 , Form1.Width * 2
Refresh method

Refresh method causes the form to be redrawn . Basically Visual Basic automatically calls this method at every opportunity , but you can use it to update your look instantly .

example :

For n = 1000 To 1 Step -1 Label1.Caption = CStr ( i ) Label1.Refresh ' Updating the label instantly . Next
SetFocus method

This method of moving the input focus to a particular control . The problem is something that often happens is that this method will lead to errors when applied to the control being in the state Disable or Invisible . For avoiding this, SetFocus method should not be used in the Form Load .

example :

Private Sub cmdAdd_Click ( ) action = flAdd Call Open Call Empty txtCCode.SetFocus ' Move the focus to the control txtCCode End Sub
methods ZOrder

ZOrder methods that control the display effect overwrite each other . You use this method to transfer control to another control above . Use a single argument to the contrary .

example :

Label1.ZOrder ' Move up Label1.ZOrder 1 ' Move to bottom
At design time , you can use Ctrl + J to move the controls forward , and Ctrl + K to move to the back of the form .

Some Common Event
The following will discuss some of the most common methods found in all intrinsic controls in Visual Basic .

Click and DblClick Event

Click event occurs when the user clicks on the left mouse button . DblClick Event thus also occur because the user did click twice.

Private Sub cmdUpdate_Click ( ) JlhRec = JlhRec DatPemakai.CCode + 1 = txtCCode.Text DatPemakai.Nama = txtNama.Text DatPemakai.Ekstension = txtEkstension.Text DatPemakai.Local = optLocal.Value DatPemakai.SLJJ = optSLJJ.Value DatPemakai.SLI = optSLI . Value Put # 1 , JlhRec , DatPemakai Position = JlhRec End Sub
At the controls like Checkbox and OptionButton , Click event also raised if there is a change in the value of the Value property coding .

ListBox and Combobox also do the same thing if its ListIndex property changed .

It is important to avoid the use of Event and DblClick Click on the same control , because it does not guarantee DblClick Event raised after the Click event occurs .

Comments