Upload
amandeep-kaur
View
38.536
Download
4
Tags:
Embed Size (px)
Citation preview
Presentation on Image controlAnd Format functions
CONTENTS Image Control Pictures Box Adding A Picture Box To A Form Setting Or Getting The Picture Adding Text to a Picture Box Formatting Text In A Picture Box Handling Picture Box Events Drawing Lines And circles In A Picture Box Picture box animation Copying Pictures To And Pasting Pictures From The
Clipboard Differences between Image and picture box controls Formatting Function
IMAGE CONTROL Image Control is used to display the images. The image control also support the property of Stretch. When Strech propery is false It will automatically
resize.
CONT’D When stretch property is set to true it will fit the image
in image control box.
PICTURE BOX Pictures Box are more complete controls than image
controls. It is used for graphics and you can load images into a
picture box. When you load an image into a picture box the picture
does not resize itself by default to fit the image as the image control does but it will if you set its AutoSize property to True.
ADDING A PICTURE BOX TO A FORM Select the picture box tool on the toolbox and double
click it to add a picture to your form. If you want the picture box to resize itself to fit the
picture you will load into it , set its auto size property to true.
If you don’t want a border on the control set its border style property to none.
You can load the picture with two different ways:- At design time:- select the picture property and
choose image.s
CONT’D At run time:- Create a command button and click on
the picture property and load the image. Private Sub Command1_Click()
Picture1.Picture= LoadPicture("C:\Users\hp\Desktop\Lighthouse.jpg")
End Sub
SETTING OR GETTING THE PICTURE• If you want to get the picture in a picture box, you also
use the picture property.• For example:-Here we copy the picture from picture1
to picture2 when the user clicks a command button:
Private Sub Command1_Click()Picture2.Picture = Picture1.PictureEnd Sub
ADDING TEXT TO A PICTURE BOX
You draw text in a picture box with its Print method passing that method the text you want to print.
Where does that text appear? It appears at the location set by the picture box’s currentX and CurrentY properties.
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.CurrentX = 30
Picture1.CurrentY = 25
Picture1.Print ("It is displaying a content in picture box")
End Sub
CONT’D
FORMATTING TEXT IN A PICTURE BOX You can use format text in a picture box using the
fontbold , fontitalic ,fontunderline properties. When you set a property to true that property applies
the next time you use the print method in the picture box.
CONT’D Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.CurrentX = 30
Picture1.CurrentY = 25
Picture1.Print ("It is displaying a content in picture box")
Picture1.CurrentX = 30
Picture1.CurrentY = Picture1.CurrentY + Picture1.TextHeight("")
Picture1.FontUnderline = True
Picture1.Print ("It is displaying a content in picture box")
End Sub
HANDLING PICTURE BOX EVENTS The click event is useful if you want to use picture
boxes as sort of image bearing buttons. If you want to know where in a picture box the user
clicked the mouse use mousedown.
Private Sub Form_Load()Picture1.ScaleMode = vbPixelsPicture1.CurrentX = 25Picture1.CurrentY = 20Picture1.Print ("Picture Box")End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > 16 And X < 83 And Y > 11 And Y < 36 Then MsgBox "you clicked the word ""picture""" End If If X > 83 And X < 125 And Y > 11 And Y < 36 ThenMsgBox "you clicked the word ""box"""End IfEnd Sub
DRAWING LINES AND CIRCLES IN A PICTURE BOX In a Picture Box you can draw lines and circle and set
points to particular colors in a picture box.
To Draw Circle Private Sub Command1_Click()
Picture1.Circle (700, 800), 500, vbRed End Sub
To Draw Line Private Sub Command2_Click()
Picture1.Line (1500, 1000)-(2500, 1000), vbRed End Sub
PICTURE BOX ANIMATION 1.Select the Project Components menu item. 2.Select the Controls tab in the Components box. 3.Select the Microsoft Windows Common Controls
item in the Components box and click onOK to close that box.
4.Add a new image list control to your program using the Image List tool in the toolbox.
5.Right-click the new image list control and select the Properties item in the menu that opens.
CONT’D 6.Click the Images tab in the Property Pages box that
opens, and load the images you want touse in the image list using the Insert Picture button.
7.Close the Property Pages box by clicking on OK.All that remains is to add the code you need. For example, here we’ve added a timer control,
Timer1to the program, set its Enabled property to False, and set its Interval property to 1000 .
COPYING PICTURES TO AND PASTING PICTURES FROM
THE CLIPBOARD You can copy the images to the clipboard , letting the
user paste them into other programs. To place data in the clipboard you use Setdata() , and
to retrieve data from the Clipboard you use getdata().
CONT’D Private Sub Command1_Click()
Clipboard.SetData Picture1.Picture
End Sub
Private Sub Command2_Click()
Picture2.Picture = Clipboard.GetData()
End Sub
DIFFERENCES BETWEEN IMAGE AND PICTURE BOX
CONTROLS
As they change shape, image controls stretch the image they contain. Picture boxes and forms do not.
Image controls are lightweight controls. This means that an image control will consume less memory and is faster to deal with than picture boxes.
CONT’D Graphics methods which allow you to draw graphics
on the fly at run time, can not be used to draw on image controls but they can draw on top of picture box controls.
A picture box’s can be used as container objects. This means other objects can be drawn and grouped inside them.
FORMATTING FUNCTION The way a value is printed or displayed is called its
formatting. Format Number Format Currency Format Percentage Format Date Time
FORMAT NUMBER This function formats the number to two decimal
places with commas.
Syntax:- Formatnumber(number)
Example:- formatnumber(87321.784)
Output:- 87,321.78
FORMAT CURRENCY This function formats a number as currency such as
dollars and cents. The number will also include a dollar sign or other
currency symbol.
Syntax:- Formatcurrency(number)
Example:- Formatcurrency(2384921.387)
Output:- “$2,384,921.39”
FORMAT PERCENT This function format its numeric argument as percent.
Syntax:- Formatpercent(number)
Example:- Formatpercent(.784)
Output:- “78.40%”
FORMAT DATETIME This function takes a date datatype argument and
format it in various ways.
Syntax:- FormatDateTime(DateExpression [,Format])
Example:-FormatDateTime(now , vblongdate)
Output:- “Wednesday,september 5,2012”