90 likes | 98 Views
CIS 338: Images on Forms. Dr. Ralph D. Westfall May, 2009. Common Controls. controls that are also used in Microsoft applications, e.g. ImageList - to hold icon images and other images used in Windows applications ListView - to display lists, such as file lists in file dialog boxes
E N D
CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009
Common Controls • controls that are also used in Microsoft applications, e.g. • ImageList - to hold icon images and other images used in Windows applications • ListView - to display lists, such as file lists in file dialog boxes • ProgressBar - to show how much has been completed e.g., a download
VB Collections • VB uses "collections" to store common controls and many other items • e.g., fields in a recordset • collection = group of objects or properties • somewhat like an array, but can be accessed by key (name), or index number lstImg.ListImages("car").Picture lstImg.ListImages(2).Picture
ImageList Control • stores images to use with other controls • stores all images in one place for use in an application, regardless of where installed • can use these images with other controls, such as a Toolbar • can use code to add images to list or change their order • can use its key or index value to get items • being phased out but still can use in code for compatibility with older applications
Setting Up an ImageList • drag ImageList control onto form (may need to Reset Toolbox to see it) • right click control, select Properties>Images>… • click Add, find common graphics at C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033VS2008ImageLibrary/Annotations&Buttons/bmp_formator link • click on each file, click Add again for as many as you want, then click OK
Using Images Without Code • can add an image to form via its Properties (not using ImageList) • click on form • find BackgroundImage property • click on ... to browse for image, then click OK • if image is smaller than the form, the images "tile" like they do on web pages
Using Images Without Code - 2 • can add a PictureBox control, and set its path in its BackgroundImage property • or use code to load image(s) when needed PictureBox1.Image = _ Image.FromFile("balloon.bmp") • the Image can be resized if the PictureBox's SizeMode = StretchImage • a PictureBox can include other controls, not just images (e.g., Button)
Using Images Without Code - 3 • can add a ToolStrip control, and set its Items property (Collection) … • then click on ListBox on ToolStrip>Button • right-click Button> • now click Import and find an image to put on the ToolStripButton VS 2003 notes
Using an ImageList with Code Private Sub Form1_Load(etc. ImageList1.Images.Add _ (Image.FromFile("[path\]beany.bmp")) 'can add other images into the ImageList '(but images are not shown yet) PictureBox1.Image = ImageList1.Images(0) ToolStrip1.ImageList = ImageList1 ToolStrip1.Items.Add _ ("[text]", ImageList1.Images.Item(0)) notes