Keypress Issue
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
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
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
EDIT
Sorry, I didn't notice that Cody already solved the problem. My code was almost the same though.
Sorry, I didn't notice that Cody already solved the problem. My code was almost the same though.
Last edited by Usman55 on Mon Jun 11, 2012 12:42 pm, edited 1 time in total.
Thats what Cody posted :?
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

Copyright Information
Copyright © Codenstuff.com 2020 - 2023