xplosiv_1

Hi,

I have added two files mode1.JPG and mode2.JPG to the resources folder in my project through the My Project screen, and I have a picture box called picbox plus a combo box with the following items in: -

Mode1

Mode2

My question is how do I get the picture box to display mode1.JPG when the user selects mode1 from the combo box and mod2.JPG when the user selects mode2 from the combo box I think my problem is pointing visual studio to my resources folder. Here is what I think the code should be: -



Private Sub modecb_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modecb.SelectedIndexChanged

If modecb.SelectedItem = "Mode 1 (Single File)" Then picbox.somthing

End Sub

Any help would be great,

Thanks,

Andy




Re: Visual Basic Language Picture Box

Brendan Grant

If youve already got the images as part of your project as embedded resources... you could simply use code like this to select the desired image:

Code Snippet

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modecb.SelectedIndexChanged

Select Case modecb.SelectedIndex

Case 0

Me.PictureBox2.Image = My.Resources.someimagefile

Case 1

Me.PictureBox2.Image = My.Resources.someotherimagefile

End Select

End Sub

Does this answer thigns for you






Re: Visual Basic Language Picture Box

xplosiv_1

Hi,

Thanks for the help, I have another similar problem, I have some check boxes and when the user checks the box a picture box goes from no picture to having a picture. My question is how do I change the picture box back so it has no picture in it My code is

Private Sub calckb_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calckb.CheckedChanged

If calckb.Checked = True Then Me.pic1.Image = My.Resources.cal

If calckb.Checked = False Then Me.pic1.Image

End Sub

Thanks,

Andy






Re: Visual Basic Language Picture Box

Solitaire

Easy:

If calckb.Checked = False Then Me.pic1.Image = Nothing






Re: Visual Basic Language Picture Box

xplosiv_1

Cheers

Should have figured that out myself Smile

Andy





Re: Visual Basic Language Picture Box

xplosiv_1

Hi,

I have another picture box related question;

Say I have two forms (frm1 & frm2), frm1 has a next button (nbtn) on it and when pressed hides frm1 and shows frm2. When I show frm2 I need the picture box to display random pictures from a collection of say 4.JPGs (1.JPG, 2.JPG, 3.JPG &4.JPG) I know how to show a picture but how do I make the picture box show a random picture from a collection of pictures.

Many thanks for your help it is much appreciated,

Andy






Re: Visual Basic Language Picture Box

Solitaire

Solution to selecting one image from among many: Place all the images in an ImageList control, found in the toolbox under Components. Prefix is iml. It will add a Component ToolTray to the bottom of your project, but it won't be seen when the program is run. Use the Images (collection) property of the ImageList control and add your images to it. Each of your images will be given the same name with an index (like an array) starting with Images(0). They are not added to the Resource folder. It is easy to add or remove images. Select a number from among the range of indexes. Then assign the image to the picture box using code. For example, if the selected number variable is num: PictureBox.Image = ImageList.Images(num)


Suppose you have 4 images in the ImageList collection. In order to select one of the images at random, your code can then be:

Dim randnum As Random = New Random
Dim selnum As Integer
selnum = randnum.Next(0, 4)

PictureBox.Image= ImageList.Images(selnum)