473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PictureBox_KeyDown or PictureBox_KeyPress not firing

Hi Gang,

Man is C# a heck of a lot harder to write events for than Visual
Basic. In any event I can't get the following code to fire when I
press a key on a picture box:
// Handle the KeyDown event to determine the type of character
entered into the control.
private void picLogo_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show(this, "you pressed a key", "keyboard",
MessageBoxButtons.OK, MessageBoxIcon.Information);

}

private void InitializeComponent()
{
this.picLogo.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.picLogo_ KeyDown);

}

I don't get any errors, but it just never fires :(.

Thanks for any and all help,
Christian Blackburn
Sep 7 '08 #1
2 2215
On Sun, 07 Sep 2008 14:28:25 -0700, Christian Blackburn
<ch*****************@yahoo.comwrote:
Man is C# a heck of a lot harder to write events for than Visual
Basic. In any event I can't get the following code to fire when I
press a key on a picture box:
[...]
Do you have VB.NET code that does the same thing and which works?

Just off the top of my head: are you sure that the PictureBox control has
focus when you are pressing the keys? My recollection is that it's one of
the "non-focusable" controls. You may be able to change that by
sub-classing PictureBox and setting the Selectable control style in the
constructor. But you may find it simpler to handle the key-press in the
container class (e.g. your form).

Keep in mind that you still have some UI issues:

-- Even if you allow PictureBox to accept focus by sub-classing, it
doesn't show focus by default. So either you'd have to add that, or you'd
have lack of good user presentation.

-- Even worse is the prospect of having a control react to key input
without having focus. In some scenarios this might work okay, but any
time you head down that path you should really reconsider whether that's
the right control/UI paradigm for the job.

Pete
Sep 7 '08 #2
On Sep 7, 2:28*pm, Christian Blackburn <christian.Blackb...@yahoo.com>
wrote:
Hi Gang,

Man is C# a heck of a lot harder to write events for than Visual
Basic. *In any event I can't get the following code to fire when I
press a key on a picture box:
Besides the stuff Peter D mentioned, which is generally good, keep in
mind the following stuff about keydown events in C#, which took me
half a day to figure out the hard way:

this.KeyPreview = true; that must be set to ‘true’ from Wizard for key
press event KeyUp or KeyDown to work, (in InitializeComponent(); it’s:
this.KeyPreview = true;)
RL
Sep 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: qaz | last post by:
For some reason my global.asa file is not firing. I have it located in the root of my website (e.g., wwwroot\mywebsite\global.asa) and I have the web site configured as an "application" in IIS. ...
0
by: Ram | last post by:
I have a start page for my application default.htm which contains four frames. header.htm login.aspx rightside.htm footer.htm login.aspx conatins username, password fields and login button....
3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
7
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when...
5
by: Datagridtextboxcolumn not firing event | last post by:
"PLEASE HELP, I NEED HELP N O W !!!" AddHandler dgtxtboxcolumn.textbox.KeyDown, AddressOf TextBoxKeyPress Private Sub TextBoxKeyPress(ByVal sender as Object, ByVal e as KeyEventArgs) End...
1
by: thedotnetarchitect | last post by:
Can anyone tell me why my page load event is firing more then once? I have a asp.net 2.0 page with four user controls and it seems that the user controls are loading but the page load event seems...
19
by: furiousmojo | last post by:
This is a strange problem. I have a project where the contents of global.asax application_error are not firing. It is an asp.net 2.0 application using web application projects. I have another...
1
by: Diana | last post by:
I've got a database that has been working successfully for a number of years now. I just added a new item - basically a field that becomes visible depending on another field's value. When I was...
5
by: Joe | last post by:
Hi I am adding a class to a ComboBox - and all is fine except that I fill the combobox on the Form_Load Method and it causes the method private void comboBox2_SelectedIndexChanged(object...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.