How to get control with no array?

I have a large number of PictureBox's, and want
to be able to change the image of any one of
them by clicking on it. How can this be done
without a control array in VB.NET?

Thanks,
Jerry

Comments

  • [b][red]This message was edited by RSlayden at 2002-11-5 12:7:57[/red][/b][hr]
    : I have a large number of PictureBox's, and want
    : to be able to change the image of any one of
    : them by clicking on it. How can this be done
    : without a control array in VB.NET?
    :
    : Thanks,
    : Jerry
    :
    Here's what I did:
    Public Class Form1
    Inhereits etc...
    Dim strPath As String = ""
    Dim intPictureBox1 As Integer
    Dim intPictureBox2 As Integer
    Dim int...etc as many PictureBoxes as you need

    #Region Windows Form etc...

    Protected Overrides Sub On_Activated(...)
    'When form is activated, load the first picture of the series into
    'each PictureBox and set a flag to indicate which picture is in the
    'box.
    PictureBox1.Image = System.Drawing.Image.FromFile(strPath & "1.bmp")
    PictureBox2.Image = System.Drawing.Image.FromFile(strPath & "2.bmp")
    PictureBox3.Image

    intPictureBox1 = 1
    intPictureBox2 = 1

    End Sub

    Private Sub PictureBox1_OnClick(...)
    intPictureBox1 += 1

    '7 is the number of pictures I was using to test with. Use your max number of pictures in the series
    if intPictureBox1 > 7 Then intPictureBox1 = 1

    Select Case intPictureBox1
    Case 1 : PictureBox1.Image = System.Drawing.Image.FromFile(strPath & "1.bmp")

    Case 2 : PictureBox1.Image = System.Drawing.Image.FromFile(strPath & "2.bmp"



    End Select
    End Sub

    Private Sub PictureBox2_Click(...)






  • : [b][red]This message was edited by RSlayden at 2002-11-5 12:7:57[/red][/b][hr]
    : : I have a large number of PictureBox's, and want
    : : to be able to change the image of any one of
    : : them by clicking on it. How can this be done
    : : without a control array in VB.NET?
    : :
    : : Thanks,
    : : Jerry
    : :
    : Here's what I did:
    : Public Class Form1
    : Inhereits etc...
    : Dim strPath As String = ""
    : Dim intPictureBox1 As Integer
    : Dim intPictureBox2 As Integer
    : Dim int...etc as many PictureBoxes as you need
    :
    : #Region Windows Form etc...
    :
    : Protected Overrides Sub On_Activated(...)
    : 'When form is activated, load the first picture of the series into
    : 'each PictureBox and set a flag to indicate which picture is in the
    : 'box.
    : PictureBox1.Image = System.Drawing.Image.FromFile(strPath & "1.bmp")
    : PictureBox2.Image = System.Drawing.Image.FromFile(strPath & "2.bmp")
    : PictureBox3.Image
    :
    : intPictureBox1 = 1
    : intPictureBox2 = 1
    :
    : End Sub
    :
    : Private Sub PictureBox1_OnClick(...)
    : intPictureBox1 += 1
    :
    : '7 is the number of pictures I was using to test with. Use your max number of pictures in the series
    : if intPictureBox1 > 7 Then intPictureBox1 = 1
    :
    : Select Case intPictureBox1
    : Case 1 : PictureBox1.Image = System.Drawing.Image.FromFile(strPath & "1.bmp")
    :
    : Case 2 : PictureBox1.Image = System.Drawing.Image.FromFile(strPath & "2.bmp"
    :
    :
    :
    : End Select
    : End Sub
    :
    : Private Sub PictureBox2_Click(...)
    :
    :

    I have a program that does this, and i did the following:

    Public Function GetImage(ByVal Imagepb As PictureBox)

    Dim openFileDialog1 As New OpenFileDialog()
    openFileDialog1.InitialDirectory = sImageLocal
    openFileDialog1.Filter = "graphics files (*.jpg)|*.jpg"
    openFileDialog1.FilterIndex = 2
    openFileDialog1.RestoreDirectory = True
    If openFileDialog1.ShowDialog() = DialogResult.OK Then
    Imagepb.Image = Image.FromFile(openFileDialog1.FileName)
    End If
    End Function

    Then all you need to do is add this to the picturebox's click event:

    GetImage(nameofpicturebox)

    Hope that helps
    -Fallen
  • Thanks, Guys. That should help.
    Sometimes the simplest thing can drive you
    nuts.

    -Jerry

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories