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.
14 posts Page 2 of 2
Contributors
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Re: Keypress Issue
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.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Keypress Issue
Usman55
EDIT

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.
Image
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Keypress Issue
MrAksel
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
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Re: Keypress Issue
hungryhounduk
Hey yeah!!

Cheers cody for that

+ rep given :)

Chris
Image
14 posts Page 2 of 2
Return to “Coding Help & Support”