Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to create my own form control.

 

Went through all the File->New->Project, selected Windows Control Library.

 

I want to capture if a function key is depressed and I tried both the KeyDown event and the Key Press event.

 

    Private Sub UserControl1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
'My Code here
End Sub
   Private Sub UserControl1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
'My Code here
   End Sub

 

However when run the control in a form, neither event is being captured.

 

What am I doing wrong?

 

I've tried putting break points at the top of the two delegates above, but the code never enters and runs.

 

Help!

  • Leaders
Posted
Make sure that your control can receive the focus, otherwise, those events will go to the form or to another control.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted
Try making the routines 'Overrides' or try calling Addhandler..... for these events in the form load .

 

So basically you're saying I need to do an Addhandler and add the keydown event to every control on my custom control? This appears to work when the control is in focus, but I need to catch this event even when the control is not in focus. Any other ideas?

Posted
Make sure that your control can receive the focus' date=' otherwise, those events will go to the form or to another control.[/quote']

 

How do I code it so that my control will capture the keydown event even if the control is not in focus. I'm developing a control that needs to scroll down when a key is hit even if the user doesn't have my control in focus.

  • Leaders
Posted

Your control needs to have focus. Why would you want to hog all of the keystrokes?

 

If your control was placed on the same form as a textbox, then the control who has focus should receive the keystrokes and nothing else.

All of the textboxes in active windows doesn't scroll down when the user hits the down button.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted
Your control needs to have focus. Why would you want to hog all of the keystrokes?

 

If your control was placed on the same form as a textbox, then the control who has focus should receive the keystrokes and nothing else.

All of the textboxes in active windows doesn't scroll down when the user hits the down button.

 

Hi Iceplug,

 

I'm not asking to hog all of the keystrokes. Here is my problem. Our company has tried to achieve a paperless office. And for a company that does data entry, this is no easy task. Teams are developing individual control modules. Mine is a composite control that is to display a scanned image. A document that must then be read by a data entry person, interpreted, and data then needs to be entered in other people's controls. There are multiple controls on a single form.

 

The problem is that my control, which displays the image must allow a data entry person to scroll through the page. They need to be able to adjust the image size so they can read the document and move through the image. They do not like the mouse. Data entry people prefer all keyboard strokes because it's faster for them. So to toggle through the page, I've written some methods in my control to move up and down, left and right through the page.

 

However I need to be able to move through the page WITHOUT requiring my control from having the focus. My control only displays the image. Other controls are responsible for handling the data entry. I would prefer not to do it at the form level because my "document viewer" is used on several data entry forms and to have to code the same repetitive keydown event for each form doesn't make sense, not to mention the fact that that's tasked to another person, and it creates a distinct problem of not being object oriented.

 

My control, must capture all keystrokes, and determine if it's a keystroke to move the image up, down, left, right. (Basically hoping to assign these to function keys or keyboard combinations.).

 

Anyways, that's my problem, which is why my control needs to receive all the keystrokes and determine if it's one of the key's pressed. Unless you know of a better way to trap an exact key such as F4 being pressed. Any solution?

Posted
Ok' date=' this is basically the direction I started heading. How do I go about this?[/quote']

 

If you set KeyPreview to True, the form will get all key messages before any control will.

 

Sounds like over kill to go the other way.

Posted
If you set KeyPreview to True, the form will get all key messages before any control will.

 

Sounds like over kill to go the other way.

 

While I agree it maybe overkill, I believe it maybe the only way to go so I can encapsulate everything into my control, without forcing another coder to code the requirements into their code. It also modularizes it.

 

I've got it working and found my solution here:

 

http://www.developer.com/net/net/print.php/11087_2193301_1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...