Be a Supporter!

pictureBox help (visual basic)

  • 637 Views
  • 7 Replies
New Topic Respond to this Topic
x-factor11
x-factor11
  • Member since: Mar. 24, 2005
  • Offline.
Forum Stats
Member
Level 11
Artist
pictureBox help (visual basic) 2012-05-02 12:14:34 Reply

This is probably an easy question to answer, but I can't seem to to do it on my own

basically, I want to create a new pictureBox and place it where a button was, but the pictureBox will not show up.

I'm not used to the code html yet, so this might look screwed up

Dim picNewX As New PictureBox


        picNewX.Width = 77
        picNewX.Height = 62
        picNewX.Image = picX.Image
        picNewX.Visible = True
        picNewX.Show()


        picNewX.Location = btnOneTwo.Location
deckheadtottie
deckheadtottie
  • Member since: Oct. 21, 2003
  • Offline.
Forum Stats
Supporter
Level 59
Programmer
Response to pictureBox help (visual basic) 2012-05-02 16:00:02 Reply

The picturebox needs to know its parent, just add this line in your code.

picNewX.Parent = Me

This was my guess as to what you wanted. Needless to say my naming conventions are terrible and should not be replicated.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim picBox As New PictureBox

        picBox.Width = 100
        picBox.Height = 100
        picBox.Image = Nothing 'add your image
        picBox.Parent = Me '//IMPORTANT, otherwise the picture box doesn't know where to go
        picBox.BorderStyle = BorderStyle.Fixed3D '// testing: see the picture box without image
        picBox.Show()

        picBox.Location = Button1.Location

        Button1.Visible = False

    End Sub

#coys

BBS Signature
x-factor11
x-factor11
  • Member since: Mar. 24, 2005
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to pictureBox help (visual basic) 2012-05-02 17:20:13 Reply

thanks, I ended up using a different method to get the images to work though.

But I hit another weird issue

Basically, I'm making a game of tic tac toe, and what happens is that when you click a button, it adds a value to an int variable that determines if it was you or the computer who made the move, you put in 1 and the computer puts in 2 (such as intOneOne = 1 means that you clicks the top left button to place your x, where the computer uses o)

Bit there is a funky error in the AI. what it does is that the ai picks a box you haven't picked, but if it picks 3, it also selects another box at random without giving that box the proper value of 2

see anything wrong in the code? intRandomPick is a number between 0 and 8

While blnStop = False


            If intRandomPick = 0 And intOneOne = 0 Then

                intOneOne = intOneOne + 2
                picOOneOne.Visible = True
                btnOneOne.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 1 And intOneTwo = 0 Then

                intOneTwo = intOneTwo + 2
                picOOneTwo.Visible = True
                btnOneTwo.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 2 And intOneThree = 0 Then

                intOneThree = intOneThree + 2
                picOOneThree.Visible = True
                btnOneThree.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 3 And intTwoOne = 0 Then

                intTwoOne = intTwoOne + 2
                picOTwoOne.Visible = True
                btnTwoOne.Visible = False
                blnStop = False
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 4 And intTwoTwo = 0 Then

                intTwoTwo = intTwoTwo + 2
                picOTwoTwo.Visible = True
                btnTwoTwo.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 5 And intTwoThree = 0 Then

                intTwoThree = intTwoThree + 2
                picOTwoThree.Visible = True
                btnTwoThree.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 6 And intThreeOne = 0 Then

                intThreeOne = intThreeOne + 2
                picOThreeOne.Visible = True
                btnThreeOne.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 7 And intThreeTwo = 0 Then

                intThreeTwo = intThreeTwo + 2
                picOThreeTwo.Visible = True
                btnThreeTwo.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            ElseIf intRandomPick = 8 And intThreeThree = 0 Then

                intThreeThree = intThreeThree + 2
                picOThreeThree.Visible = True
                btnThreeThree.Visible = False
                blnStop = True
                intDrawCollective = intDrawCollective + 1
                WinTest()

            Else

                intRandomPick = randChoice.Next(9)

            End If


        End While
x-factor11
x-factor11
  • Member since: Mar. 24, 2005
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to pictureBox help (visual basic) 2012-05-02 17:53:30 Reply

ok, nevermind, the other random button selected when 3 is does give that slot's variable the proper number

x-factor11
x-factor11
  • Member since: Mar. 24, 2005
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to pictureBox help (visual basic) 2012-05-02 18:02:28 Reply

nevermind as in the 3 thing is still a problem, but that isn't

deckheadtottie
deckheadtottie
  • Member since: Oct. 21, 2003
  • Offline.
Forum Stats
Supporter
Level 59
Programmer
Response to pictureBox help (visual basic) 2012-05-03 09:37:16 Reply

I'm going to need to see the entire programme in order to help you better. You can zip it up and PM me/post it here if you would like.

That while loop looks very suspect to me, but I can't really say until I see this code in a clearer context.


#coys

BBS Signature
nameistaken1
nameistaken1
  • Member since: May. 21, 2007
  • Offline.
Forum Stats
Member
Level 16
Game Developer
Response to pictureBox help (visual basic) 2012-05-03 14:15:11 Reply

Under Else if 3:

blnStop = False

should be

blnStop = True

BBS Signature
deckheadtottie
deckheadtottie
  • Member since: Oct. 21, 2003
  • Offline.
Forum Stats
Supporter
Level 59
Programmer
Response to pictureBox help (visual basic) 2012-05-03 15:52:30 Reply

At 5/3/12 02:15 PM, nameistaken1 wrote: Under Else if 3:

blnStop = False

should be

blnStop = True

Ah, nice catch.


#coys

BBS Signature