 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 is used to display the images.
 The image control also support the property of Stretch.
 When Strech propery is false It will automatically
  resize.
   When stretch property is set to true it will fit the image
    in image control 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.
 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
 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
•   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
   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
 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.
 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
 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 = vbPixels
Picture1.CurrentX = 25
Picture1.CurrentY = 20
Picture1.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 Then
MsgBox "you clicked the word ""box"""
End If
End Sub
   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
 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.
 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 .
 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().
 Private Sub Command1_Click()
Clipboard.SetData Picture1.Picture
End Sub

 Private Sub Command2_Click()
Picture2.Picture = Clipboard.GetData()
End Sub
   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.
 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.
 The way a value is printed or displayed is called its
  formatting.
 Format Number
 Format Currency
 Format Percentage
 Format Date Time
 This function formats the number to two decimal
  places with commas.
Syntax:- Formatnumber(number)
Example:- formatnumber(87321.784)
Output:- 87,321.78
 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”
 This function format its numeric argument as percent.
Syntax:- Formatpercent(number)
Example:- Formatpercent(.784)
Output:- “78.40%”
 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”
Image contro, and format functions in vb

Image contro, and format functions in vb

  • 2.
     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
  • 3.
     Image Controlis used to display the images.  The image control also support the property of Stretch.  When Strech propery is false It will automatically resize.
  • 4.
    When stretch property is set to true it will fit the image in image control box.
  • 5.
     Pictures Boxare 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.
  • 6.
     Select thepicture 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
  • 7.
     At runtime:- 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
  • 8.
    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
  • 9.
    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
  • 11.
     You canuse 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.
  • 12.
     Private SubForm_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
  • 13.
     The clickevent 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.
  • 14.
     PrivateSub Form_Load() Picture1.ScaleMode = vbPixels Picture1.CurrentX = 25 Picture1.CurrentY = 20 Picture1.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 Then MsgBox "you clicked the word ""box""" End If End Sub
  • 15.
    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
  • 17.
     1.Select theProject 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.
  • 18.
     6.Click theImages 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 .
  • 19.
     You cancopy 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().
  • 20.
     Private SubCommand1_Click() Clipboard.SetData Picture1.Picture End Sub  Private Sub Command2_Click() Picture2.Picture = Clipboard.GetData() End Sub
  • 21.
    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.
  • 22.
     Graphics methodswhich 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.
  • 23.
     The waya value is printed or displayed is called its formatting.  Format Number  Format Currency  Format Percentage  Format Date Time
  • 24.
     This functionformats the number to two decimal places with commas. Syntax:- Formatnumber(number) Example:- formatnumber(87321.784) Output:- 87,321.78
  • 25.
     This functionformats 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”
  • 26.
     This functionformat its numeric argument as percent. Syntax:- Formatpercent(number) Example:- Formatpercent(.784) Output:- “78.40%”
  • 27.
     This functiontakes a date datatype argument and format it in various ways. Syntax:- FormatDateTime(DateExpression [,Format]) Example:-FormatDateTime(now , vblongdate) Output:- “Wednesday,september 5,2012”