Re: Keypress Issue
Posted: Mon Jun 11, 2012 6:48 am
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:
If thats the case then you could do something like this:
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
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 :?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
If thats the case then you could do something like this:
Code: Select all
Probably not the shortest way of doing it though. 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