Tips and trick (part 1)
This section provides various tips and tricks used to apply programming in Visual Basic version 6.0.
Character Password (*)
You must already know that in certain applications that use passwords, text boxes are used to fill the password always bring the star character (*) if you type something into it. This of course meant that no one else can read the actual characters you type. To create a text box to remove the character * (or even other characters) is very easy to do, namely to fill in the characters you want on the property PasswordChar text box control. After that if you type something into the text box, then the characters that will appear is the character that you enter into the PasswordChar property.
Center Screen
Often if your application is run, the location of the application form on the monitor screen is not settled. Sometimes on the top left, sometimes in the middle, sometimes at the bottom. For those of you who like cleanliness, maybe this will seem annoying. There is an easy trick for an application form are always situated in the middle of the screen, if executed, that is by changing the properties StartUpPosition into 2 - CenterScreen, or form an image right click on the Form Layout window, select Startup Screen Position ® Center.
Default Size Control
To add a control to the form, you use click and drag the mouse to form the control in the form. If you want to use a control with the default size, then there is a faster way, ie double-click the control icon. Automatically in the form will be added to control the default size. While the position of course still have to set it manually.
If you are a Visual Basic user starting from the early versions, you must know that the display IDE (Integrated Development Environment) or the display window of the Visual Basic 6.0 differs from previous versions. You can change the look of the IDE Microsoft Visual Basic 6.0 to resemble the previous versions by clicking Tools ® Options menu. Select the Advanced tab, enable the check box SDI Development Environment. Exit the Visual Basic 6.0, then run again. Display the Visual Basic 6.0 IDE will change
Adding Images In the Command Button
So far, you always use the Caption on the Command Button. You can also add pictures on the Command Button to add your application appeal. For that there are some properties that need to be changed, namely:
Property Value
Style 2 - Graphical
Caption [You can clear these properties]
Picture [Pictures to be added to the Command Button]
DownPicture [Image in Command Button when clicked]
Example:
Make a form, add a Command Button and change its properties as follows:
Property: Value
Style: 2 - Graphical
Caption: [blank]
Picture: C: \ Windows \ Cursors \ No_l.cur
DownPicture: C: \ Windows \ Cursors \ No_m.cur
For Picture and DownPicture property, if the cursor files are given in the example does not exist on your computer, you can replace yourself with another file.
Run your application, consider what happens if the Command Button is clicked.
PopUp Menu
Sometimes you want to display a menu by right-clicking on an object. Menu like this is called PopUp Menu. It's easy. Make a menu with the menu editor, then turn off options that are visible in the dialog box editor menu. That must be considered is, the choice is only visible to non-active menutitle its course, while for each menuitem, this visible option must remain active. Then use the mouse down event on the object you want to show the PopUp Menu, then add the following syntax:
PopUpMenu menutitle
Remember, by using the mouse down event, which mouse button is clicked can be captured by taking a particular value of the parameter button. To the right mouse button, button parameter value is 2.
Example:
Make a form, add menus and Picture Box control into it. Fill up the menu and your image. Do not forget to disable the check box visible in the menu editor to menutitle it. In the picture box control to add code as in listing 1.
Listing 1. MouseDown Event in Picture1
Private Sub Picture1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
PopupMenu mnuFile
End If
End Sub
Run the application. A menu will appear when you right-click the Picture Box control.
Editing Some Controls Together
To edit multiple controls at once, using a combination of shift + click or ctrl + click to activate the option on some controls.
For example, consider Figure 2. In the drawing, the three Command Button on the form are located too close to the left. To move to the middle of all three at once, select the Command Button is third with a combination of shift + click or ctrl + click. After that you can move the control all three at once.
Tab Order
Sometimes for one thing we can not use the mouse in operating an application, such as the mouse is defective. So we had to use the keyboard in running an application. Or maybe our application is an application used in the store cashier who was deliberately not given a mouse. In circumstances where we have to use the keyboard, then to move from one control to another control that we use the tab key. For it in designing a form, we also need to adjust the control sequence to be active if the tab key is pressed. To set the sequence very simple way, namely by adjusting the TabIndex property of each control. Which directly controls the focus if the application is run will have a TabIndex 0, then if we hit the tab key, then the next active control with TabIndex is 1, and so on.
For certain cases, the use of the tab key to move from one control to another control is not efficient, and to replace the desired tab button enter key. To replace the tab key to enter, the tricks that can be used is to use the KeyPress event. KeyAscii value to enter is 13. If the value is met keyAscii 13, then the next control that wants to become the focus should be subject setfocus methods.
Adding a Control Array In The Run-Time
Generally we add controls to the form when designing these forms (at design time), but Visual Basic also provides the facility to increase the number of control array at run-time by using the Load statement.
Example:
Make a form and add a Command Button. Change property Indexnya with numbers 0.
Into the Command Button is added as the program code listing 2.
Listing 2. Click on Command1 Event
Private Sub Command1_Click (Index As Integer)
Load Command1 (1)
Command1 (1). Left = Command1 (0). Left
Command1 (1). Top = Command1 (0). Top + Command1 (0). Height
Command1 (1). Caption = "New Command"
Command1 (1). Visible = True
End Sub
Note that the procedures have Command1_Click Index As Integer parameters that must be added.
Run the application. If the Command Button is clicked, it automatically added a new Command Button directly below.
Well, hopefully the tips and tricks for helping you to create applications with Visual Basic.