0% found this document useful (0 votes)
15 views52 pages

Unit 2

The document provides a comprehensive guide on working with menus and advanced controls in Visual Basic (VB), including creating a notepad application with menu functionalities. It covers various controls such as scroll bars, sliders, image lists, toolbars, and rich text boxes, along with their properties and event handling. Additionally, it includes sample code snippets for implementing these features effectively in a VB project.

Uploaded by

Nivya babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views52 pages

Unit 2

The document provides a comprehensive guide on working with menus and advanced controls in Visual Basic (VB), including creating a notepad application with menu functionalities. It covers various controls such as scroll bars, sliders, image lists, toolbars, and rich text boxes, along with their properties and event handling. Additionally, it includes sample code snippets for implementing these features effectively in a VB project.

Uploaded by

Nivya babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 52

Unit 2

❖ Working with menu :


Menu Designing in VB ,adding a menu to a
form,modify and deleting menu item, adding
shortcut key, menu using the common dialog
box , attaching code to the event ,creating
submenu.
❖ Advanced Control in VB:
Scroll Bar,Slider Control,Image List,Toolbar,
Tree View,List View,Rich Text Box,,Status
Bar,Progress Bar,Cool bar,
Menu Properties
Attaching code to the event
Menu using the common dialog box
Font dialog box
CREATION OF NOTEPAD
Step1:Create menu and their submenu by using menu editor.
Step2:Right click on project menu. Click on components. It will open a dialog
box ,In this dialog box check on the microsoft common dialog
box .0,microsoft rich text box tools
step3 :It will appear above two controls in the tools box sets its properties as
shown below
object property
common dialog box name cd
richtext box name-rt
Step4: draw the richtextbox control on the form according to form size and also place the common dialog box control on the form.

step5: Write the code:

Private Sub newmnu_click()


Dim x as integer
if rt<> “” then
x=Msg “do you want to save ,” yes,no)
if x=yes then cd.showsave
else
Exit Sub
End if
End if
rt.text=” ”
form1.caption=” untitled notepad”
End sub
Private Sub openmnu_click()
cd.showopen
rt.filename=cd.filename
form1.caption=”untitled”&cd.filename
End sub

Private Sub savemnu_click()


cd.showsave
rt.savefile=cd.filename
End sub

Private Sub exitmnu_click()


unload me
End sub
Private Sub forecolor_click()
cd.showcolor
rt.selcolor=cd.color
End sub
Private Sub backcolor_click()
cd.showcolor
rt.backcolor=cd.color
End sub
Private Sub cutmnu_click()
clipboard.seltext rt.seltext
rt.seltext=nullstring
End sub
Private Sub copymnu_click()
clipboard.seltext rt.seltext
End sub
Private Sub pastemnu_click()
rt.seltext=clipboard.gettext
End sub
Scroll Bar
The horizontal and vertical scroll bar are
widely used in window app. Scroll bar
provides an interactive way to move
through a list of information and make
great input device.The horizontal scrollbar
and vertical bar control such thing as
allow the user to set a value from a range
or to major progress both type of scrollbar
are comprise of three area that can be click
or drag to change the scroll bar value
clicking an end arrow increment the scroll bar a small amount ,clicking
the bar area increment the scroll box a large amount and dragging the
scroll bar provides continuous motions
Properties
1. Large Changes:Increment edit two or subscrited from the scroll bar
value property when the bar area is clicked
2. Max:Sets Lowerbound or the range from -32768 to 32767
3. Min:Sets Upperbound or the range from -32768 to 32767
4. Small change: The increment edit two or subscripted from the
scroll bar value property when the either of the scroll arrow is
clicked
5. Value: Indicate the current position of the thumb with in the scroll
bar
METHOD:-

Change :event is triggered after the scroll bar position has been
modified.Use this event to retrieve the value property after any change
in the scroll bar

Scroll Bar:-Event reject continuously whenever the scroll bar is being


moved
Program to change the Label color with the
help of scroll bar

Control Properties
Label Caption
Scroll Bar1 Max(255) ,Min
(0)

Largechange (10)
Scroll Bar2 Max(255) ,Min
(0)

Largechange (10
Scroll Bar3 Max(255) ,Min
(0)

Largechange (10
General
Dim r,g,b as integers
Private sub form_Load()
r=g=b=0
End Sub

Private sub Vscroll1_change()


r=vscroll.value
Label1.backcolor=RGB(r,g,b)
End Sub

Private sub Vscroll2_change()


g=vscroll.value
Label1.backcolor=RGB(r,g,b)
End Sub

Private sub Vscroll3_change()


b=vscroll.value
Label1.backcolor=RGB(r,g,b)
End Sub
Image List Control
● An ImageList Control contains a collection of images that can be used by
other Windows Common Control
● It does not appeare on the form at run time.
● It serve as a container for icon that are accessed by other control such as
ListView,TreeView,TabStrip and ToolBar controls.

To add Image list control in the tool box:


1.Click on “Start” . Then select “All Programs, Microsoft Visual Studio 6.0
and Microsoft Visual Basic 6.0.” .
2. Select “Standard EXE” from the list in the New Project dialog box and
click on “Open.” Click on “Project” on the menu bar, then select
“Components” from the drop-down menu.
3. Scroll down the list in the box until Microsoft Windows Common Controls
6.0 (SP4) is visible. Click on the checkbox to select the component and then
click on “OK.” All components show in the Toolbox.
To add images to the image list control:

● Right click on Image control a popup menu is open choose


properties option.A Properties Page is open .
● Click on Images Tab and insert the image as you want.
● To insert more than one picture then click on Insert Picture
Button
Toolbar
The Toolbar provides the user quick access to the most commonly used
functions of a program. A toolbar can be used stand-alone or as a
complement to the program's menu structure.
Adding a slider to a program

1. Select the Project/Components menu


item, and click the Controls tab
the Components box that opens.
2. Select the Microsoft Windows
Common Controls item
3. Close the Components box by
clicking on OK.
To build the Toolbar Demo sample
project, perform the following steps:
1. Create the menu with the help of
menu editor .

2. Creating a toolbar in VB requires the use of


two controls. The first is the ImageList control,
which contains the images that will be used for
the toolbar buttons. The second control is the
Toolbar itself. These controls are two of nine
controls that are part of Microsoft Windows
Common Controls. To make these controls
accessible to your VB project, go to the Project
menu in the VB IDE and select Components:
Click OK. The ImageList
and Toolbar, along with the
TreeView, ListView, Slider,
StatusBar, ProgressBar,
TabStrip, and ImageCombo
will appear in your toolbox
as shown below. (These
other controls will be
covered in separate topics;
for now we will focus just
on the ImageList and
Toolbar.)
3. Double-click on the ImageList
control to bring it onto the form

With the ImageList selected,


click F4 to bring up the property
list and name the ImageList
imlToolbarIcons.

4. With the ImageList control


selected on the form, right-click it
and select Properties from the
context menu. This causes the
property page for the ImageList to
be displayed:
5. Click the Images tab. The Property
Pages dialog looks like the screen-shot
below:

The task at hand now is to repeatedly


click the Insert Picture button, select
an image, and set the Key property
until you have loaded all of the desired
images.
6. The next order of business is to bring the toolbar control onto the
form. Do so by double-clicking the Toolbar control on the toolbox.
By default, the toolbar will be aligned with the top of the form, below
the menu, if you have one.
7. With the toolbar selected and set the (Name) property to tbrMenuOpts.
Then, right-click the toolbar and select Properties to bring up the Property
Pages dialog, as shown below. On the General tab, set ImageList to
"imlToolbarIcons" – remember, the toolbar must get its images from the
images stored in an ImageList control. Also, set the Style property to "1 –
tbrFlat" (the default is "0 – tbrStandard").
8. On the Buttons tab of the Property Pages dialog, click the Insert
Button, and set the following properties:

o Set the Key property to "New". The Key property of a toolbar


button is a string that uniquely identifies that button in the collection
of buttons of a given toolbar. In this version of the sample program,
the Key property is used to identify which button the user pressed (the
button can also be identified by the Index property, but it is easier to
use the Key property).

o Set the ToolTipText property to "New". This is text that will


pop up in a little yellow label when the user moves the mouse over the
button.

o Set the Image property to "1" or "New". This is how you tie an
image in the ImageList control to a button on the toolbar. The value
you type for the Image property here refers to either the Index or the
Key property of the desired image in the ImageList control.
Click the "Insert Button" button again.
Leave the Key, ToolTipText, and
Image properties alone, but set the
Style property to "3 – tbrSeparator". If
you look back at the screen-shot
showing the Flat toolbar Style, you'll
see that a vertical line separates each
button in the toolbar. This is actually
done by setting the Style property of
every other button to "3 –
tbrSeparator". The Property Pages
dialog box should look like this:
9. code the Click event for the toolbar, which will test which button the
user pressed, then call the corresponding menu click event procedure
(and the menu events have already been coded). For example, if the user
clicks the Open button on the toolbar, we simply want to call the
mnuFileOpen_Click event procedure.

Private Sub tbrMenuOpts_ButtonClick(ByVal Button As


MSComctlLib.Button)

VB passes a Button object to the event procedure; this button object


represents the toolbar button that the user clicked. To see what button the
user clicked, test the Index or Key property of the Button object (using
standard object.property syntax, like "Button.Index" or "Button.Key").
In the sample program, "Button.Key" is used. The coding is as follows:
Private Sub tbrMenuOpts_ButtonClick(ByVal Button As
MSComCtlLib.Button)

Select Case Button.Key


Case "New"
mnuFileNew_Click
Case "Open"
mnuFileOpen_Click
Case "Save"
mnuFileSave_Click
Case "Print"
mnuFilePrint_Click
Case "Help"
mnuHelpAbout_Click
End Select
End Sub
Slider Control

Slider and ScrollBar are very similar in use. Both controls have an
Orientation property to select between vertical and horizontal modes.
They both derive from a common base class, RangeBase. This provides
Minimum and Maximum properties, which define the range of values the
control represents, and a Value property holding the currently selected
value. It also defines SmallChange and LargeChange properties, which
determine by how much the Value changes when adjusted with the arrow
keys, or the Page Up and Page Down keys, respectively. The
LargeChange value is also used when the part of the slider track on either
side of the thumb is clicked.Whereas slider controls have a fixed-size
thumb, the thumb on a scroll bar can change in size
Adding a slider to a program

1. Select the Project/Components menu item, and click the Controls tab
the Components box that opens.
2. Select the Microsoft Windows Common Controls item
3. Close the Components box by clicking on OK.
4. The Slider tool appears in the toolbox at this point. Add a slider to te
form in the usual way.
5. Set the slider's Orientation property to ccOrientationHorizontal (value 0,
the default) or ceOrientationVertical (value 1) to specify the orientation
you want.
6. Set the slider's Min, Max, SmallChange, and Large Change values
as you want them.
7. Add the code to a slider’s change event

Private Sub Form_Load()


slider1.Max=255
Slider1.min=0
End Sub

Private Sub Slider1_click()


Text1.Backcolor=RGB(0,0,Slider1.value)
End Sub
Rich text Box Control

The rich text box control alow user to display enter and edit text while
also providing more advanced formatting feature then the conventional
text box control.The rich text box control is a custom control we will
need to add it to the tool box if It is not already ther ,To do this :- Select
project>component>MS Window common control 6.0

Private sub command1_click()


cd1.showprinter
rtb1.setprint printer.hdc
End sub
Status Bar Control
With the help of status bar you can easily display information about
date,time and another details about the application and the environment
to the user. It display the status of the application.Each status divide in
16 panels .This control is a custom control we will need to add it to the
tool box if It is not already ther ,To do this :- Select
project>component>MS Window common control 6.0

Private sub command1_click()


statusbar1.panel1.text=”commannd1 button”
End sub
Private sub command2_click()
statusbar1.panel1.text=”commannd2 button”
End sub
List View Control
List View Control is used
to display a list of item
along with icons.The
item property of the list
view control allow you
to add and remove items
from it .
Private sub command1_click()
Listview1.listitems.add
text=textname.text
listview1.listitem.item(1)

Listview1.listitems.add
text=textroll.text
listview1.listitem.item(1)

Listview1.listitems.add
text=textcourse.text
listview1.listitem.item(1)

End sub
Progress Bar

The loading bars are used for any type of application and software.
The main question is how to create a progress bar in visual basic,
this concept is used for giving the visualization about the current
status of the current process and computer operation, such as
downloading, transferring files, installation, and more. If you also
don't know about this topic then read this post properly you will get
your answer.
Design the form as per the given image
Visual basic progress bar source code
Private Sub Form_Load()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
ProgressBar1.Value = ProgressBar1.Value + 5
load.Caption = "Please wait! Setup is loading....."
per.Caption = ProgressBar1.Value & "%"
If ProgressBar1.Value = ProgressBar1.Max Then
Timer1.Enabled = False
MsgBox "Installation is completed successfully"
Unload Me
End If
End Sub

You might also like