Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009.

Similar presentations


Presentation on theme: "CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009."— Presentation transcript:

1 CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009

2 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

3 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

4 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

5 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

6 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

7 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)

8 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 Images Without Code - 4 click on Toolbar, view Properties click to right of Buttons property … click Add button to add Buttons click to right of ImageIndex property (right side of same form where adding buttons) and select image from dropdown list

9 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 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Static i As Integer i = i + 1 If i >= ImageList1.Images.Count() Then i = 0 PictureBox1.Image = ImageList1.Images(i) End Sub


Download ppt "CIS 338: Images on Forms Dr. Ralph D. Westfall May, 2009."

Similar presentations


Ads by Google