Page 2 of 2

Re: Keypress Issue

Posted: Mon Jun 11, 2012 6:48 am
by CodenStuff
Im half asleep so im not sure I understand the problem correctly but ill try anyway lol.

Are you saying that you have 11 pictureboxes and each one represents a letter in your name "hungryhound" and you have keypress code something like this:
Code: Select all
Private Sub Form1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.H Then
            PictureBox1.BackgroundImage = My.Resources.h
            PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
            e.SuppressKeyPress = True
        End If
        If e.KeyCode = Keys.U Then
            PictureBox2.BackgroundImage = My.Resources.u
            PictureBox2.SizeMode = PictureBoxSizeMode.Zoom
            e.SuppressKeyPress = True
        End If
        If e.KeyCode = Keys.N Then
            PictureBox3.BackgroundImage = My.Resources.n
            PictureBox3.SizeMode = PictureBoxSizeMode.Zoom
            e.SuppressKeyPress = True
        End If
        If e.KeyCode = Keys.G Then
            PictureBox4.BackgroundImage = My.Resources.g
            PictureBox4.SizeMode = PictureBoxSizeMode.Zoom
            e.SuppressKeyPress = True
        End If
    End Sub
When you press "H" is load in PB1 and when you press "U" it loads in PB2 and so on?...if thats correct then the problem is your name has 2 "H"'s in it but the code you have when you press H puts an image in PB1 so when you press H again its loading the image into PB1 again and not PB7 where the second "H" is in your name :?

If thats the case then you could do something like this:
Code: Select all
 Private Sub Form1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.H Then
            If PictureBox1.BackgroundImage Is Nothing Then
                PictureBox1.BackgroundImage = My.Resources.h
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
                e.SuppressKeyPress = True
            Else
                PictureBox7.BackgroundImage = My.Resources.h
                PictureBox7.SizeMode = PictureBoxSizeMode.StretchImage
                e.SuppressKeyPress = True
            End If
        End If
        If e.KeyCode = Keys.U Then
            If PictureBox2.BackgroundImage Is Nothing Then
                PictureBox2.BackgroundImage = My.Resources.u
                PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
                e.SuppressKeyPress = True
            Else
                PictureBox9.BackgroundImage = My.Resources.u
                PictureBox9.SizeMode = PictureBoxSizeMode.StretchImage
                e.SuppressKeyPress = True
            End If
        End If
        If e.KeyCode = Keys.N Then
            If PictureBox3.BackgroundImage Is Nothing Then
                PictureBox3.BackgroundImage = My.Resources.n
                PictureBox3.SizeMode = PictureBoxSizeMode.StretchImage
                e.SuppressKeyPress = True
            Else
                PictureBox10.BackgroundImage = My.Resources.n
                PictureBox10.SizeMode = PictureBoxSizeMode.StretchImage
                e.SuppressKeyPress = True
            End If
        End If
        If e.KeyCode = Keys.G Then
            PictureBox4.BackgroundImage = My.Resources.g
            PictureBox4.SizeMode = PictureBoxSizeMode.StretchImage
            e.SuppressKeyPress = True
        End If
        If e.KeyCode = Keys.R Then
            PictureBox5.BackgroundImage = My.Resources.r
            PictureBox5.SizeMode = PictureBoxSizeMode.StretchImage
            e.SuppressKeyPress = True
        End If
        If e.KeyCode = Keys.Y Then
            PictureBox6.BackgroundImage = My.Resources.y
            PictureBox6.SizeMode = PictureBoxSizeMode.StretchImage
            e.SuppressKeyPress = True
        End If
        If e.KeyCode = Keys.O Then
            PictureBox8.BackgroundImage = My.Resources.o
            PictureBox8.SizeMode = PictureBoxSizeMode.StretchImage
            e.SuppressKeyPress = True
        End If
        If e.KeyCode = Keys.D Then
            PictureBox8.BackgroundImage = My.Resources.d
            PictureBox8.SizeMode = PictureBoxSizeMode.StretchImage
            e.SuppressKeyPress = True
        End If
    End Sub
Probably not the shortest way of doing it though.

Re: Keypress Issue

Posted: Mon Jun 11, 2012 11:51 am
by Usman55
EDIT

Sorry, I didn't notice that Cody already solved the problem. My code was almost the same though.

Re: Keypress Issue

Posted: Mon Jun 11, 2012 12:03 pm
by MrAksel
Thats what Cody posted :?

Re: Keypress Issue

Posted: Mon Jun 11, 2012 1:30 pm
by hungryhounduk
Hey yeah!!

Cheers cody for that

+ rep given :)

Chris