Академический Документы
Профессиональный Документы
Культура Документы
Home Tutorials
Level:
Written By TheVBProgramer.
You've already seen in the previous topic that with an Image control, you can set it's Picture property at design time by going
to Picture property, clicking the ellipsis (), and selecting a file from the Load Picture dialog box. Recall that the main types
of files that can be assigned to an Image control are .bmp, .jpg, .ico, and .wmf.
The Image control has a Stretch property, which is set to False by default. When the Stretch property is
False, the Image control will automatically resize itself to expand or contract to the size of the picture
that is assigned to it. If instead you want the image to fill the specific size that you make the Image
control, set the the Stretch property to True, which will cause the picture you assign to the Image control
to automatically expand or contract to conform to the size of the control. Depending on the type of
image, the image may or may not appear distorted when stretched this is something you need to
experiment with.
You can also set the Picture property of an image control in code by using the LoadPicture function, which loads a picture
from a file into the control at run-time. The LoadPicture function takes a file name as an argument. Sample syntax is:
imgMyPic.Picture = LoadPicture("C:\SomeDirectory\SomeSubDir\MyPic.bmp")
"Picture" is the default property of the image control, so the above statement could have been written as:
imgMyPic = LoadPicture("C:\SomeDirectory\SomeSubDir\MyPic.bmp")
(Note: In my earlier VB programming, I would typically omit the default property of controls; however, I
now advocate explicitly coding all properties so I recommend keeping the ".Picture" on there.)
Keep in mind the following general points about setting the Picture property of a control using
LoadPicture at run-time compared to selecting a file for the control's Picture property at design-time:
When you set the picture at design-time, that picture becomes embedded in your application (it is
stored in the .frx file of the form that is using it). Therefore, your program is bigger, but runs faster
because the picture is in memory when your program loads.
When you use LoadPicture, the program is smaller because the image is not embedded in the
application, but resides in a separate file. However, the image processing is slower because the
program must access it from disk.
To clear the picture from an image control, use the LoadPicture function with an empty set of parentheses:
imgMyPic.Picture = LoadPicture()
If you have more than one image control on a form, you can copy a picture from one image to another via an assignment
statement like this:
imgPic1.Picture = imgPic2.Picture
- or -
imgPic1 = imgPic2
A common technique to change an image on a form at various points in the program is to use a number
of image controls as a "repository". The images in the "repository" will all have their Visible property set
to False. At the desired time, the program will assign one of the images from the "repository" to the
image to be displayed. The following sample program demonstrates this technique.
The sample program displays a traffic light that alternates color from green to yellow to red every half of
a second. All images used are icons from the folder:
Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Traffic.
To build the sample program, use the figure below as a guide to place the indicated controls on the
default form and set the properties of the controls to the values indicated in the callouts.
Option Explicit
End Sub
When the program runs, the traffic light will alternate in color between green, yellow, and red at intervals
of one half of a second:
Like the Image control, the PictureBox control can be used to display images. However, the PictureBox can do much more.
Like the Frame control, the PictureBox is a "container" control, meaning that other controls can be placed inside it. In
addition, the PictureBox can be used to generate run-time graphics and to display text. As a general rule of thumb, if your
application requires the special capabilities of the "heavyweight" PictureBox, then use it; but if all you want to do is display an
image, then use the "lightweight" Image control.
The Form has both a Picture property and an Icon property. The Form's Picture property is used to
display an image directly on the form; this can be suitable for displaying a background image. In the
screen shot below, the Form's Picture property was set to a file called "Santa Fe Stucco.bmp". The
image is displayed starting in the upper left-hand corner of the form and cannot be moved or resized. If
you want to display an image directly on the form like this, and you want the image to fill the entire
background of the form, you must make sure the image to be used is the same size or larger than the
size you want to make the form. (If the image you want for the background of the form is too small, use
an Image control that you set to be the same size as the form with its Stretch property set to True, as
was done in the previous topic's sample program with the "clouds.bmp" image.)
Note: To clear the Picture property at design-time, highlight the entry for the Picture property ("(Bitmap)"
in this case), and press the Delete key.
The Form's Icon property is used to set the icon that is displayed in the left-hand corner of the Form's
title bar. In the screen shot below, the Form's Icon property was set to the SUN.ICO icon from the
Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements folder.
When you compile a VB program, the icon used for the resulting EXE is determined by the setting of the
Icon property of the Form you specify on the "Make" tab of the project's properties sheet (accessed from
the IDE's Project menu item). As shown below, the icon that will be used for this application's EXE will
be the "sun" icon from "Form1". If the project had more than one form, then you could choose which
form's icon would be used for the EXE by selecting the appropriate form name from the "Icon:"
drop-down box:
The Command Button control has a Style property, which, when set to 1Graphical, enables you to
display a picture on the button via the command button's Picture property. (Also when the Style is
set to 1-Graphical, you can change the BackColor of the button, which you cannot do when the Style is
set to 0-Standard.)
If the command button also has a non-blank value for its Caption property, the text of the caption will
appear below the picture. (Note: In VB6, you cannot specify the position (left, right, below) of the picture
relative to the caption on the command button: the picture will always appear above the caption. A
custom button control would be needed to display the picture to the left or right of the caption on the
button.)
The screen shot below shows two command buttons with images (the images shown are from a custom
icon set):
The command button also has a DisabledPicture property, which allows you to specify an alternative
image to be displayed on the button when the Enabled property is set to False:
If you don't use the DisabledPicture property, the system will "do its best" to render a disabled image
based on the original what it comes up with may or may not be acceptable to you:
Another technique used with "picture buttons" is to place only a picture on the button and leave the
Caption blank then use an adjacent Label control to describe the function of the button, as shown in
the "switchboard" type screen below:
Using Images with Other Controls
Images can be used with many with other controls. In later topics, a set of controls called the Windows
Common Controls will be explored. This set of controls comprises the ToolBar, TreeView, ListView,
TabStrip, StatusBar, and several others. These controls are used in conjunction with an ImageList
control, which serves as a repository for images to be used for items within the controls (i.e. icons for the
Toolbar buttons, TreeView nodes, ListView list items, etc.) The screen shot below shows a portion of a
screen used by an application that uses a ToolBar, TreeView, and ListView.
As mentioned previously, Visual Studio 6/Visual Basic 6 comes with a set of over 900 graphic files (over
500 of which are icons). When Visual Studio 6 or VB 6 is installed, the Graphics folder is NOT installed
by default (whoever is installing it must explicitly check the "Graphics" option during the appropriate step
of the installation). Assuming that the Graphics are installed, by default they will be placed in the
directory structure shown below:
The Icons folder contains 13 subfolders. As a reference, and for convenience, screen shots of the
contents of the icon folders are shown below:
Even with all of the icons and other graphic files included with VB, you may not find images that you
deem suitable for your application. Not all "categories" of icons that you might expect are present in the
included collections, and those that are included would be regarded by some as "dated" (the offering of
included icons has not changed since VB 3.0 back in 1995). Fortunately, there are numerous resources
on the Internet for icon collections (ranging in price from free to several hundred dollars) as well as
resources for working with icons (creating your own and/or modifying existing icons).
Post to Facebook
Post to Twitter
Add to LinkedIn
Similar links
Learn howto use the Visual Basic DateDi function
DateTime Functions
Dim sec As Integer Dim min As Wed, 03/07/2012 - 00:18 Maani (not veried)
timer code
sec = sec + 1
ProgressBar1.Value = sec
If ProgressBar1.Value = 59 Then
ProgressBar1.Value = 1
End If
If sec = 59 Then
t1 = "0"
sec = 0
min = min + 1
End If
If min = 59 Then
t2 = "0"
min = 0
hou = hou + 1
End If
If sec >= 10 Then
t1 = ""
End If
If min >= 10 Then
t2 = ""
End If
If hou >= 10 Then
t3 = ""
End If
Time.Text = t3 & hou & ":" & t2 & min & ":" & t1 & sec
form load event
sec = 0
min = 0
hou = 0
t1 = "0"
t2 = "0"
t3 = "0"
Reply to comment (VB6) Sat, 09/29/2012 - 22:02 gure drawing skills (not veried)
When I initially commented I clicked the "Notify me when new comments are added" checkbox and now each time a
comment is added I get four emails with the same comment.
Is there any way you can remove people from that service?
Many thanks!
problem relating option button Wed, 02/01/2012 - 23:16 Anonymous (not veried)
i want set image for option button without changing its style property to graphical..plz someone help me....
FirstComeFirstServed Tue, 01/10/2012 - 18:02 Leo Grande (not veried)
can you send me the design and program of the FirstComeFirstServed?using vb=2008
hi I have Downloaded many icons from the internet. The format of icons is correct, (16x16,32x32,64x64; .ICO, .PNG) But
when i used it in VB6, it says, "Invalid Picture"! Please tell Me Any solution or Suggest any site where i can nd icons
which compatible with VB6.
I'm working with objects and ListImage toolbar but I sent the error 5, as if he had lled a limit of objects, where do I can
extend this limit?
add my code with the problem Thu, 08/18/2011 - 12:37 Vicente (not veried)
Set imgX = ImageList1.ListImages.Add(, "search", LoadPicture(App.Path & "\zoom.gif", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "nsearch", LoadPicture(App.Path & "\document.gif", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "markCaf", LoadPicture(App.Path & "\document_edit.gif", vbLPSmallShell, ,
10, 10))
Set imgX = ImageList1.ListImages.Add(, "undoCaf", LoadPicture(App.Path & "\interact.gif", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "addAcc", LoadPicture(App.Path & "\user_add.gif", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "adjust", LoadPicture(App.Path & "\other.gif", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "other", LoadPicture(App.Path & "\mark.gif", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "locks", LoadPicture(App.Path & "\lock.gif", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "Send", LoadPicture(App.Path & "\excel2_app.ico", vbLPSmallShell, , 10, 10))
Set imgX = ImageList1.ListImages.Add(, "chgName", LoadPicture(App.Path & "\user_black.gif", vbLPSmallShell, , 10,
10))
Set imgX = ImageList1.ListImages.Add(, "close", LoadPicture(App.Path & "\close.gif", vbLPSmallShell, , 10, 10))
-->Set imgX = ImageList1.ListImages.Add(, "Empty", LoadPicture(App.Path & "\folder_open.gif", vbLPSmallShell, 10,
10))
Set imgX = ImageList1.ListImages.Add(, "Download", LoadPicture(App.Path & "\down.gif", vbLPSmallShell, 10, 10))
is possible that you can upload image or pictures by using a command button rather than going to imagelist properties
and then insert pictures?
i mean instead of using insert pictures to properties is there possible that my command button do it for me?? please send
me some codes thanks:D
I have problem on how to load a picture on registration Form Sun, 07/10/2011 - 01:34 Abdirizak (not veried)
Please help I have problem araising from my database. I have made database about my institution in the registration form
I want to add all required information grathering from the students I hit the problem of picture while I am using visual
basic 6.0 on the form of registry I want to add student's photos when is registering I have no Idea about it nor code and
how to store in SQL the type of sring i choosing.
please if you know that help
I have problem on how to load a picture on registration Form Sun, 07/10/2011 - 01:33 Abdirizak (not veried)
Please help me I have problem araising from my database. I have made database about my institution in the registration
form I want to add all required information grathering from the students I hit the problem of picture while I am using visual
basic 6.0 on the form of registry I want to add student's photos when is registering I have no Idea about it nor code and
how to store in SQL the type of sring i choosing.
please if you know that help
limit the file size of photos to be uploaded Thu, 04/21/2011 - 15:33 Hendri Alrasim (not veried)
how the writing is right when we want to make the image upload facility in VB6 using the common dialog and limit the le
size of photos to be uploaded?
am using stringless connection but i can't move next, or previous rather it is moving rst and last. and i don't know how i
can load picture into datareport so that when i move next the picture will change to the next person's picture. thanks in
anticipation
how to get picture from common dialog control to chose any picture and load into the access database
please help..... how to apply my laptop camera in the form to capture and saving a pictures...thanks
hi can you help me plz how to put my camera on the form, what VB tool i use an
d what is the code...plzz.......
please...help!!! I need a VB code for loading images, interpret and detect image from the scanner...
Please...help!!I need this badly...
how to insert image in visual basic Thu, 12/30/2010 - 06:01 Anonymous (not veried)
how to insert image in VB .after make the form the image is invisiable .after click that is visiable.plz send me coding of
that program
I can't conceive how to do Mon, 03/05/2012 - 02:28 Orlando Seo (not veried)
I can't conceive how to do this and get animated images. Could give give brief comments and a couple of lines of
code to get me started.
help with saving command using data enviroment Wed, 12/08/2010 - 03:35 Anonymous (not veried)
hi all,
i have a project to do and am using dataenviroment but i cant save the les to my database
please help
Sir/Mam
Iwant to know how to start Vb project what Procedure?
Mugees Ahmad
Loading an image in VB using Vc++. Mon, 08/23/2010 - 00:10 Asma (not veried)
HOW CAN I ADD THE ANIMATED FILE INTO IMAGE Wed, 08/18/2010 - 08:40 Anonymous (not veried)
BOX
Hello... anyone can tell me how to add the animated graphics les into my vb form and how can i run it...
if you want to add animation, use .gif les in loading pictures.. or just use Flash animations..
Animation wrong info Tue, 08/02/2011 - 22:00 Anonymous (not veried)
animated .gif doesnt work with Default Picture components. You need to ip it with looping
re animaion looping of picturebox. I can't conceive how to do this and get animated images. Could give give
brief comments and a couple of lines of code to get me started.
Dear Sir
Elango.K
+91-9842604398
sir,
i want to keep some image paths in an excel sheet column. can i use
variablename=selection.value
Image1.Picture = LoadPicture(variable name insted of path)
Load Image at Run Time Sat, 05/15/2010 - 08:41 Karthick VR (not veried)
Hi, Can anyone help me how to create a program to ask for the user to load image at run time and display it?
Load Image at run time. Tue, 11/30/2010 - 19:25 Don (not veried)
End With
ErrorHandler:
End Sub
Thanks all Works fine for me. Sun, 10/23/2011 - 16:14 Anonymous (not veried)
Thanks all
Works ne for me. Now I can load my pictures.
Sizing a webcam picture for thumbnail Tue, 03/09/2010 - 02:40 PhilipSA (not veried)
Hi. We have web cam pics as .jpg's, but when I load the pic in VB6, I want the pic sized to t a thumbnail size, but all I can
actually see is the top corner of the actual pic.
Then I tried using an image, which shows the whole pic, but the control has now been resized at run time to be the size of
the pic which is way too big. I want a standard thumbnail size!
Any suggestions?
vb6 image from access Sat, 02/20/2010 - 20:10 ian fuentes (not veried)
hi there.. i just want to create a program in vb6 that is using ms access as its database, i use adodc to connect them.. i
already bind those with the textboxes but the problem is i dont know how to bind the images in order to view them on vb6
along with their corresponding names and information. can you please help..
heres my email..
ians_acess@yahoo.com
re: vb6 image from access Sat, 08/14/2010 - 23:22 t13b (not veried)
I was able to accomplish this by using a dataSet. With the DataSet, I changed the Image column type to 'image'
before dragging the dataset onto the form.
Now, just to gure out how to upload images from the application to the database. I hope this helps you some
though---if not too little too late :)
Depending on the type of Thu, 02/16/2012 - 03:25 Michael Jackson Lyrics (not veried)
Depending on the type of image, the image may or may not appear distorted when stretched this is
something you need to experiment with.
how can i bind picture to vb6 using ms access Tue, 02/16/2010 - 16:53 ian fuentes (not veried)
hi im just a 1st yr collegestudent, i just want to ask ahm i used adodc connection in vb and access, im trying to build a
program in vb. data are from access but adodc cconnection only show text,can i also bind a picture on it along with their
corresponding details from access,,, pls help
use this code to bind images Sun, 06/13/2010 - 05:29 Mr.P (not veried)
hi, However how can you give me the code on how I am going to save the picture in the database or in the ms access?.
Answer : how to bind images with pictureboxes Mr.p Sun, 06/13/2010 - 05:28 Anonymous (not veried)
Or
you can create a column in MS acess with the locations of your picture corresponding to the information
and in your form do this:-
1.create a text box text1 which reads your picture location
Private Sub Timer1_Timer()
If Text1.Text = "" Then
else
pictureshow.picture = text1.text
End If
End Sub
Answer : how to bind images with pictureboxes Sun, 06/13/2010 - 05:03 Anonymous (not veried)
about image and tables with calculation problem Sat, 10/03/2009 - 01:36 jatin (not veried)
Dear Sir
Sir i have some problem. i m creating a project in visual basic. but i have some problem in this as given below:-
1. i want to that how we can insert a picture on a form in a passport size. and i want when we open the any record of
person then his photo also show. please give me a source code for this.
2. i want to when we open a person record his details also show like, total amount due of his etc. and also a print
help about ICO files Sat, 09/19/2009 - 08:32 Pleasure (not veried)
what type of les can i use in command buttons? i downloaded a winrar le with ico pictures and when i loaded it in
properties of command button it returns an error msg: invalid picture. what picture is VALID for command buttons? is
there a pixel limit?
VB6 doesn't supports icon les with modern characteristics i.e. 256x256 or true color+alpha etc. In this case you can
use a free Icon tool like the IconFX (http://icofx.ro) to actually "strip down" the unsupported Images from the ICO le. I
really don't remember which properties are supported actually, but I believe it must be something like 8 bit color with
a maximum of 16x16 pixels. But i 'm not sure start to strip down save and try. Trial and Error my friend...
u can use .ico les for command buttons. Extract the downloaded winrar of .ico les and store to a particular location
and then open it or specify the path correctly. u will be able to insert the .ico image perfectly.
loading picture from file in Visual Basic Thu, 04/30/2009 - 19:17 JIGer (not veried)
I make an inquiry program in database with over 100 employees and id like to put a picture in the program
with the corresponding person i've searched ?
image from web browser Tue, 04/14/2009 - 22:24 mizkhyz (not veried)
How Can I? Please..... Thu, 03/19/2009 - 05:10 Pogi Rodriguez (not veried)
I am working on my thesis and i am just a beginner using vb. I need codes for my program that will upload picture
together with other text data of the picture. I also need to edit what I uploaded after wards. I don't know how to control
the database. thanks. I hope somebody can help me with this.
hello
i am currently learning to use visual basic at my school during my computers class and am still a begginer.
as a little home project, i want to create a countdown timer that counts down from 20 seconds when open, using images
(eg. image of number 20, number 19 etc.) and when this timer reaches 1 (1.bmp) i want it to run a le (i can make the
program run a le, just not when it reaches 1), though i am unsure of what sytax to use to do this.
i was thinking:
OR
or something along thoes lines, this may be fairly jumbled and hard to understand but please help.
Reply for Image List Mon, 03/23/2009 - 00:59 Anonymous (not veried)
One solution would be to rstly rename your les as 1, 2, 3, 4, ....20, save all of them in a particular folder and then
use the following timer code:
rstly create a variable as int A and set its value to 20. This will be used to refer to your image
Else
A = A-1
End If
End Sub
Hi all,
I have a requirement where I have to access the image les at the server from a remote machine located and connected
thru internet. I am able to do the same in loval machine. But, how to access the les in remote server or machine. can any
one please send me the code snippet of the same to shankarravi18@redimail.com. its damn urgent......Thanx
Ravishankar
This is my code
------------------------------------------
Option Explicit
Public Function LoadPicture(MyPic As Image)
imgMyPic.Picture = LaodPicture("f:\MyPic.jpg ")
End Function
-------------------------------------------
Try this
Option Explicit
Public Function LoadPicture(MyPic As Image)
imgMyPic.Picture = LaodPicture(MyPic)
End Function
You spelt load wrong Fri, 03/06/2009 - 02:44 Anonymous (not veried)
Im not sure whether you just copied it wrong here but you spelt load wrong (laod insted of load) try changing that
then it should work
Help with Image problem Fri, 10/24/2008 - 11:04 Kercyn
Image problem I need help with! Sat, 06/28/2008 - 09:01 Anonymous (not veried)
VB to save pictures from computer Wed, 08/27/2008 - 09:07 Anonymous (not veried)
CommonDialog1.ShowOpen
Image1.Picture = LoadPicture(CommonDialog1.FileName)
lblRegistrationCard = CommonDialog1.FileName
From this common dialoug control you can access any picture from your computer
rock Sat, 02/18/2012 - 03:23 play a ash game (not veried)
using LoadPicture at run-time compared to selecting a le for the control's Picture property at d
Thanks a lot.. I 've been looking this kind of code for very long time.. However how can you give me the code on
how I am going to save this in my database.
I am having lots of scanned objects in .jpg format and the scanned objects are bigger than the monitor screen size and
hence i am facing problem in displaying the scanned object within the image box control. If someone could tell me how to
enable the user to navigate the whole scanned object using the scroll bars of the image control.
I've updated my Visual Basic 6 with SP6 and there is no longer stretch property of the PictureBox. Can someone tell me
how to make an image stretch using the new features? Or is there some bug or a problem? 10x in advance
The PictureBox control does NOT have a Stretch property! Only the Image control has a Stretch property.
This has got nothing to do with your using SP6. There's no kind of bug in your Visual Studio/Basic 6.0.
The PictureBox control does have an AutoSize property, but it doesn't really do the same thing as Stretch. You can
give AutoSize a try, but I suggest you use the Image control instead.
:-)
- SDR
Wow! its realy for beginners..it could help a lot for a neophite like me
>< Thu, 04/19/2007 - 01:54 Roda
Me too !
Unless otherwise noted, all content on this site and in the source samples is Copyrighted 2011 by the owner of vb6.us.
All rights reserved - Contact Information