0% found this document useful (0 votes)
60 views

Program For Enlarging Circle VB

This document discusses how to add and manipulate graphics in Visual Basic forms and controls. It covers loading images into PictureBox and Image controls, changing images at runtime, and using graphics methods to distort or enlarge images. Special effects are demonstrated like making an Image control behave as a custom button. LoadPicture() is introduced as a way to load images from the file system.

Uploaded by

Boobalan R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Program For Enlarging Circle VB

This document discusses how to add and manipulate graphics in Visual Basic forms and controls. It covers loading images into PictureBox and Image controls, changing images at runtime, and using graphics methods to distort or enlarge images. Special effects are demonstrated like making an Image control behave as a custom button. LoadPicture() is introduced as a way to load images from the file system.

Uploaded by

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

PROGRAM FOR ENLARGING CIRCLE AND ADJUSTING

SPEED

INTRODUCTION

In VB, graphics capabilities are usually associated with drawing lines, boxes, or
otherwise manipulating the display. Graphics are usually created on something, which in the
case of VB is either the printer, the screen, or the picture control. All three represent a surface
to which graphics can be applied. No other control supplied with VB supports the graphics
features. In Visual Basic 6.0, various graphics methods and properties are used to draw on a
Form or PictureBox control. Graphics in Visual Basic 6.0 are based on the Windows
Graphics Device Interface (GDI) APIs.

ADD GRAPHICS TO A FORM

1. Open a Standard EXE project and name it SmplGrfx. Name the default form
frmMain. Set the form's Caption property to Simple Graphics.

2. Add a PictureBox to the form by double-clicking the PictureBox icon in the


toolbox or by selecting the PictureBox and then drawing the control on the form.
Name the PictureBox picMain.

3. Add an Image control to the form by using the same procedures as those described
in step 2 for the PictureBox. Name the Image control imgMain.

4. Size and place the PictureBox and Image controls where it is required to them on
the form

5. Select the picMain PictureBox. Go to the Picture property in the Properties


window and open the Load Picture dialog by clicking the ellipsis button

6. Go to the Windows directory and select Bubbles.bmp. When you click the Open
button, this bitmap will appear in the PictureBox.

1
7. Set the value of the AutoSize property of the picMain PictureBox to True. This
enlarges the area of the PictureBox to accommodate the size of the bitmap
Bubbles.bmp.

8. Select the Image control and set the value of the Picture property to the bitmap
Triangles.bmp. (This file is also in the Windows directory.) Do this the same way
you added a picture to the PictureBox. You can't set the AutoSize property, however,
because it isn't supported by the Image control.

9. Save and run your

CHANGING A PICTURE AT RUNTIME

It is possible to change the graphic assigned to the Picture property of a PictureBox or


Image control at runtime by changing the value of the control's Picture property.

CHANGE A CONTROL'S PICTURE PROPERTY AT RUNTIME

1. Reopen the SmplGrfx.vbp project that you created earlier.

2. Add a CommandButton to the form and name it cmdChange. Set the value of the
Caption property to Change the graphic.

3. Add the following code to the cmdChange_Click() event procedure:

picMain.Picture = imgMain.Picture

4. Save and run the code

SETTINGS FOR THE CUSTOM BUTTON IMAGE CONTROL

Private Sub Form_Load()

imgMain.Picture = imgUp.Picture

End Sub

Private Sub imgMain_MouseDown(Button As Integer, _

2
Shift As Integer, X As Single, Y As Single)

imgMain.Picture = imgDown.Picture

End Sub

Private Sub imgMain_MouseUp(Button As Integer, _

Shift As Integer, X As Single, Y As Single)

imgMain.Picture = imgUp.Picture

End Sub

6. Set the value of the Visible property for the Image controls imgDown and imgUp to
False.

7. Set the following code in the Click event procedure of the Image control imgMain:

MsgBox "I am a custom button!"

8. Save and run the code

ADDING GRAPHICS TO FORMS WITH LOADPICTURE()

If graphic file has to be loaded into a PictureBox or Image control from hard disk, the
LoadPicture() function can be used:

MyPicture = LoadPicture(strFilePath)

In this syntax,

MyPicture is a picture for a PictureBox or Image control.


LoadPicture is the function name.
strFilePath is a string that references the exact location on the hard disk of the
graphics file that is required to load. This string must be in quotation marks.

3
THE CLICK() EVENT PROCEDURE OF THE COMMANDBUTTON

Private Sub cmdAssign_Click()

Dim strFilePath As String

Query the option buttons to see which one

`has been checked.

If optBitmap.Value = True Then

`Show the bitmap graphic

picDisplay.Picture = picBitmap.Picture

ElseIf optIcon.Value = True Then

`Show the icon graphic

picDisplay.Picture = picIcon.Picture

ElseIf optList.Value = True Then

`Assign the exact path of the graphic in the file

`list box to the strFilePath string variable.

strFilePath = File1.Path & "\" _

& File1.List(File1.ListIndex)

`Load the picture from disk and assign it to the

picDisplay.Picture = LoadPicture(strFilePath)

End If

End Sub

4
The application loads the selected file from disk into the PictureBox picDisplay by using the
LoadPicture() function.

CREATING SPECIAL GRAPHIC EFFECTS

In the project MoreGrfx.vbp, after users assign a picture to the PictureBox picDisplay,
they can decide to distort the picture by clicking the CommandButton cmdDistort. When this
button is clicked, the picture in the PictureBox is assigned to the Picture property of the
Image control imgDistort with the following statements:

imgDistort.Width = picDisplay.Width * 1.5

imgDistort.Picture = picDisplay.Picture

THE CODE TO ENLARGE A PICTURE

Private Sub cmdEnlarge_Click()

Dim dSizeRatio As Double

dSizeRatio = picDisplay.Width / picDisplay.Height

imgDistort.Width = imgDistort.Height * dSizeRatio

End Sub

REFERENCES

http://www.vb-helper.com/howto_closeup_map2.html

http://www.vb-helper.com/index_graphics.html

http://uap.unnes.ac.id/ebook/programming%20references/Mastering%20Visual%20Basic%2
06/ch17/ch17.htm

You might also like