Image contro, and format functions in vb

39,074 views
38,877 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
39,074
On SlideShare
0
From Embeds
0
Number of Embeds
137
Actions
Shares
0
Downloads
33
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Image contro, and format functions in vb

  1. 1.  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
  2. 2.  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.
  3. 3.  When stretch property is set to true it will fit the image in image control box.
  4. 4.  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.
  5. 5.  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
  6. 6.  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:UsershpDesktopLighthouse.jpg") End Sub
  7. 7. • 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.Picture End Sub
  8. 8.  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 = vbPixelsPicture1.CurrentX = 30Picture1.CurrentY = 25Picture1.Print ("It is displaying a content in picture box")End Sub
  9. 9.  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.
  10. 10.  Private Sub Form_Load()Picture1.ScaleMode = vbPixelsPicture1.CurrentX = 30Picture1.CurrentY = 25Picture1.Print ("It is displaying a content in picture box")Picture1.CurrentX = 30Picture1.CurrentY = Picture1.CurrentY + Picture1.TextHeight("")Picture1.FontUnderline = TruePicture1.Print ("It is displaying a content in picture box")End Sub
  11. 11.  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.
  12. 12.  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
  13. 13.  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
  14. 14.  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.
  15. 15.  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 .
  16. 16.  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().
  17. 17.  Private Sub Command1_Click()Clipboard.SetData Picture1.PictureEnd Sub Private Sub Command2_Click()Picture2.Picture = Clipboard.GetData()End Sub
  18. 18.  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.
  19. 19.  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.
  20. 20.  The way a value is printed or displayed is called its formatting. Format Number Format Currency Format Percentage Format Date Time
  21. 21.  This function formats the number to two decimal places with commas.Syntax:- Formatnumber(number)Example:- formatnumber(87321.784)Output:- 87,321.78
  22. 22.  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”
  23. 23.  This function format its numeric argument as percent.Syntax:- Formatpercent(number)Example:- Formatpercent(.784)Output:- “78.40%”
  24. 24.  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”

×