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 1 of 2
Contributors
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Keypress Issue
hungryhounduk
Hey

I have 11 pictureboxes and on certain keypresses it puts pictures into the pictureboxes.

If i type HUNGRYHOUND it displays a picture in each picturebox depending on the key pressed.

**My problem is, If i type the same letter twice it does not appear, but leaves the picturebox blank, I know thats because i have already used it, But how do i code it to carry on accepting keys after they have been used?

If that makes sense :)

Code: Select all
If e.KeyCode = Keys.H Then
            PictureBox1.BackgroundImage = My.Resources.h
            PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
            e.SuppressKeyPress = True
any help will be appreciated and + Reps given :P

Chris
Image
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Keypress Issue
MrAksel
Have you tried to comment out the SuppressKeyPress line? I didn't think that it would affect later events but you can try.
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
Skillful
Skillful Coders
Skillful Coders
Posts: 969
Joined: Tue Nov 16, 2010 10:07 am

Re: Keypress Issue
Skillful
First of all set the form's KeyPreview property to true. You can do this from the property grid or adding the following code under the Form_Load event :
Code: Select all
Form.KeyPreview = True
Then change:
Code: Select all
e.SuppressKeyPress = True
To:
Code: Select all
e.Handled = True
And tell me if it works. Typed all of this from my mom's mobile lol :P
Instead of LOL use this -
LSIBMHBIWFETALOL

Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Re: Keypress Issue
hungryhounduk
Hey Skillful
I am afraid that does not work for me

Chris
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 MrAksel
I am afraid that does not work for me either

Chris
Image
User avatar
Ffenixw0rks
VIP - Donator
VIP - Donator
Posts: 152
Joined: Sun Jun 19, 2011 2:51 pm

Re: Keypress Issue
Ffenixw0rks
Maybe you can create booleans to see if key was already pressed?
Then if you need put pictures and change bools...
Image
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Keypress Issue
Usman55
Ffenixw0rks wrote:
Maybe you can create booleans to see if key was already pressed?
I was having the same idea but that would take a lot of useless coding space and also slow down the program slightly. It would look stupid, lol.
Image
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Keypress Issue
M1z23R
I think it is better to use .image instead of .backgroundimage property, maybe they are the same, maybe not, idk. And are u using form.keydown or ?
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Keypress Issue
MrAksel
What ffenix suggested wouldn't slow down the program, but it wouldn't solve the problem. M1z23r BackgroundImage and Image are two different things, but changing it wont have any visible effects.
I have no solution myself, it's a weird problem. The only thing I can think of is: hungryhound, do you use PictureBoxX.BackgroundImage.Dispose() at any point? If so, remove that line and it should work. Another tip; The SizeMode property only affects the drawing of the selected Image, not the BackgroundImage :)
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
it's a weird problem. The only thing I can think of is: hungryhound, do you use PictureBoxX.BackgroundImage.Dispose() at any point? If so, remove that line and it should work. Another tip; The SizeMode property only affects the drawing of the selected Image, not the BackgroundImage
Hey
No i haven't used PictureBoxX.BackgroundImage.Dispose() in the coding
It's still a Mystery :)

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