Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Thursday, August 11, 2011

VB-104 : Creating Tool Bar with Click Event

How to create a Tool Bar in VB and make a Click Event For the created Buttons.
(Taken from VB-Tutorial CDs ..)

Select, Project--> Components.
Then a Dialog Box will appear and select Microsoft Windows Common Controls 6.0 and Click OK, as given below :

Then , we can see that ,some tools are added to the ToolBar , as shown below : 
Note the Actual ToolBar and  ToolBar after adding the Control:
     

  

   Add 2 Controls called ToolBar and Image List to our Form (The added Controls will not visible in the form while running ) , as given below :

     
 ==================================================================================================================================================================  
Changing  Properties to the 2 added controls :

 (A)Right Click the second Control  Image List to get the property page as shown below :
It has  3 options as GeneralImage and Color

  • Select the General Tab ...From there , change set the size as 32X32  and Click ok.
  • Next select the Image Tab from the Property Page of ToolBar ..It is shown after the belw given Image.
=========================
  • General Tab :

Image Tab :     

Next select the Image Tab from the Property Page of ToolBar .And select Insert Picture to insert pictures .If we insert 4 pictures , then the Image Count will be 4 .


 (B)Right Click the first Control  ToolBar to get the property page as shown below :
It has  3 options as General, Buttons and Picture 

  • Select the General Tab ...From there , change the third option Image List from None to Image List1 , and Click OK.
  • Next select the Buttons option from the Property Page of ToolBar .It is shown after the belw given Image.
=========================
  • General Tab :

  • Button Tab :       
Click Insert Button ,Give a Caption for the inserted picture ..We can insert any number of pictures as we like.(Note that , the Index of each inserted image will be 1,2,3....etc.upto the selected image)

Run the Project :


We can see a ToolBar in the Form , and with 4 Buttons.
But , There is only one click event for all this 4 Buttons. 
Each Buttons has a property named Index

Using this Index Property , we can write Code for each Buttons .

(That will follow by another Program..)


(D) Errors :
If found any errors while running your VB program, or want to put your comment about any  program , please click Comment section , to post.
====================================================================Back to Home   &  VB
    ===========================================================

    VB-103 : Program Using Menu Bar

    Creating a menu and attaching code .
     (Taken from VB-Tutorial CDs ..)


    Refer Design a Menu Bar and Create a Menu as per the format given
    And , Creating Tool Bar with Click Event 

    Select Tools--> Menu Editor and create menus as per given below :






       (A)Program Design : 






    (B) Property(Controls Used) :

    • File & Exit are the main menus
    • Two sub menus of File are Colors & Size
    • The sub menu of Color is Set Color
    • The sub menu of Set Color is White , Red & Blue
    Note while giving Names (mnucolors,mnusize...etc) .These are important while attaching code to the object.
    You can watch this Video to know about adding Menu Bar into our form.


    (C) Attaching Code to the Object :



    Private Sub Form_Load()
    mnuwhite.Enabled = False
    mnuwhite.Checked = True
    End Sub
    Private Sub mnublue_Click()
    Form1.BackColor = vbBlue
    mnuwhite.Enabled = True
    mnuwhite.Checked = False
    mnured.Enabled = True
    mnured.Checked = False
    mnublue.Enabled = False
    mnublue.Checked = True
    End Sub
    Private Sub mnuexit_Click()
    End
    End Sub
    Private Sub mnularge_Click()
    Form1.WindowState = 2
    End Sub
    Private Sub mnured_Click()
    Form1.BackColor = vbRed
    mnuwhite.Enabled = True
    mnuwhite.Checked = False
    mnured.Enabled = False
    mnured.Checked = True
    mnublue.Enabled = True
    mnublue.Checked = False
    End Sub
    Private Sub mnusmall_Click()
    Form1.WindowState = 0
    End Sub
    Private Sub mnuwhite_Click()
    Form1.BackColor = vbWhite
    mnuwhite.Enabled = False
    mnuwhite.Checked = True
    mnured.Enabled = True
    mnured.Checked = False
    mnublue.Enabled = True
    mnublue.Checked = False
    End Sub



    (D) Errors :
    If found any errors while running your VB program, or want to put your comment about any  program , please click Comment section , to post.
    ====================================================================

    ===========================================================

    VB-102 : Declare a function(Pass by reference)

     To declare a function (Pass by reference Method)
    (Taken from VB-Tutorial CDs ..)


    Refer  Add 2 numbers(Pass by Value method)
    Refer the same program in normal programming code : Simple Programs(3) 


    (A)Program Design : 


    (B) Property(Controls Used) :
    • 3 Labels,3 TextBoxes , One Command Button

    (C) Attaching Code to the Object :

    Private Sub Command1_Click()
    Dim answer As Integer
    answer = Add(Val(Text1), Val(Text2))
    Text3.Text = answer
    End Sub
    ---------------------------------------------------------------------------------------------------------
    Public Function Add(ByRef first As Integer, ByRef second As Integer) As Integer
    Dim f As Integer
    f = first + second
    Add  =  f
    End Function




    (E) Errors :
    If found any errors while running your VB program, or want to put your comment about any  program , please click Comment section , to post.
    ====================================================================

    ===========================================================

    VB-101 : Add 2 numbers(Pass by Value method)

    Add 2 number by Pass by Value method.

     Taken from VB-Tutorial CDs ...

    Refer the same program in normal programming code : Simple Programs(3)  and Declare a function(Pass by reference)



    (A)Program Design : 





    (B) Property(Controls Used) :
    • 3 Labels
    • 3 TextBoxes
    • One Command Button



    Refer  Simple Programs(3) to know the details about property.


    (C) Attaching Code to the Object :



    Private Sub Command1_Click()
    Dim first As Integer, second As Integer, answer As Integer
    First = Val(Text1.Text)
    Second = Val(Text2.Text)
    Answer = Add(First, Second)
    Text3.Text = Answer
    End Sub
    ------------------------------------------------------------------------------------------------
    Public Function Add(a As Integer, b As Integer) As Integer
    Dim f As Integer
    f = a + b
    Add = f
    End Function



    Double click on Form and go to code window ( For Function)
    Select Tools--> Add Procedure
    Give Name - Add
    Type  - Function
    Scope - Public



    (E) Errors :
    If found any errors while running your VB program, or want to put your comment about any  program , please click Comment section , to post.
    ====================================================================
    ===========================================================