473,703 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keypress event back to caller from control

Tom
I have a VB.NET user control that I wrote - this control has three or four
other controls on it (textbox, combobox, datetime picker, etc). Now,
whenever the control is on a form and the user enters anything into the
textbox (for instance) I trap the keypress event to handle some stuff (i.e.
if it is an enter key, etc). Now, once I am done with handling the keypress
event for the textbox, I then need to pass that keypress event BACK to the
main form that is hosting the control. I can't just define another KeyPress
event and try a RaiseEvent because the control already has a keypress event.

I must be brain dead or something today, because normally I should be able
to figure this out but it just isn't coming to me. Once I am done with the
KeyPress event in my control, how can I pass that event (and it's data -
i.e. what key was pressed) back to the host form?

Tom
Nov 20 '05 #1
4 4526
Can you override the controls KeyPress event in the parent form, and then
just call the KeyPress event for the parent form when your done?

Or else raise a public event in the control and catch it in the parent form
(passing along
(ByVal sender As Object, ByVal e As System.EventArg s)) info and then call
the KeyPress event in the parent?

public class MyControl()

Public Event OnTextBox1KeyPr ess (ByVal sender as Object, ByVal e As
System.EventArg s)

Private Sub TextBox1_KeyPre ss (ByVal sender as Object, ByVal e As
System.EventArg s)

'Do something

RaiseEvent OnTextBox1KeyPr ess (sender,e)

End Sub

End Class

Public Class MyForm

Dim testcontrol as New MyControl

Private Sub testcontrol_Key PressHandler (ByVal sender as Object, ByVal
e As System.EventArg s) _ Handles testcontrol_OnT extBox1KeyPress

MyForm_KeyPress (sender,e)

End Sub

Private Sub MyForm_KeyPress (ByVal sender as Object, ByVal e As
System.EventArg s) Handles MyForm.KeyPress

'Do Something

End Sub

End Class

I'm sure there is a better way, but this should work fairly easy as well.

Eric Dreksler

"Tom" <to*@nospam.com > wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a VB.NET user control that I wrote - this control has three or four
other controls on it (textbox, combobox, datetime picker, etc). Now,
whenever the control is on a form and the user enters anything into the
textbox (for instance) I trap the keypress event to handle some stuff (i.e. if it is an enter key, etc). Now, once I am done with handling the keypress event for the textbox, I then need to pass that keypress event BACK to the
main form that is hosting the control. I can't just define another KeyPress event and try a RaiseEvent because the control already has a keypress event.
I must be brain dead or something today, because normally I should be able
to figure this out but it just isn't coming to me. Once I am done with the
KeyPress event in my control, how can I pass that event (and it's data -
i.e. what key was pressed) back to the host form?

Tom

Nov 20 '05 #2
Is this for validation?

If so you could use the CausesValidatio n approach.

Schneider
"Eric Dreksler" <ericd AT accessoneinc DOT com> wrote in message
news:#r******** *****@TK2MSFTNG P10.phx.gbl...
Can you override the controls KeyPress event in the parent form, and then
just call the KeyPress event for the parent form when your done?

Or else raise a public event in the control and catch it in the parent form (passing along
(ByVal sender As Object, ByVal e As System.EventArg s)) info and then call
the KeyPress event in the parent?

public class MyControl()

Public Event OnTextBox1KeyPr ess (ByVal sender as Object, ByVal e As
System.EventArg s)

Private Sub TextBox1_KeyPre ss (ByVal sender as Object, ByVal e As
System.EventArg s)

'Do something

RaiseEvent OnTextBox1KeyPr ess (sender,e)

End Sub

End Class

Public Class MyForm

Dim testcontrol as New MyControl

Private Sub testcontrol_Key PressHandler (ByVal sender as Object, ByVal e As System.EventArg s) _ Handles testcontrol_OnT extBox1KeyPress

MyForm_KeyPress (sender,e)

End Sub

Private Sub MyForm_KeyPress (ByVal sender as Object, ByVal e As
System.EventArg s) Handles MyForm.KeyPress

'Do Something

End Sub

End Class

I'm sure there is a better way, but this should work fairly easy as well.

Eric Dreksler

"Tom" <to*@nospam.com > wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now,
whenever the control is on a form and the user enters anything into the
textbox (for instance) I trap the keypress event to handle some stuff

(i.e.
if it is an enter key, etc). Now, once I am done with handling the

keypress
event for the textbox, I then need to pass that keypress event BACK to the main form that is hosting the control. I can't just define another

KeyPress
event and try a RaiseEvent because the control already has a keypress

event.

I must be brain dead or something today, because normally I should be able to figure this out but it just isn't coming to me. Once I am done with the KeyPress event in my control, how can I pass that event (and it's data -
i.e. what key was pressed) back to the host form?

Tom


Nov 20 '05 #3
"Tom" <to*@nospam.com > wrote in message news:<#r******* *******@TK2MSFT NGP12.phx.gbl>. ..
I must be brain dead or something today, because normally I should be able
to figure this out but it just isn't coming to me. Once I am done with the
KeyPress event in my control, how can I pass that event (and it's data -
i.e. what key was pressed) back to the host form?

Tom


Do you need to return the sender as well? Otherwise, calling
<control>.OnKey Press(e), where e is the event data object you
intercepted, should do it, right?

John Fiala
jcfiala523-at-hotmail.com
http://www.livejournal.com/users/fiala_tech/
Nov 20 '05 #4
Actually the form will get the event first if the Form.KeyPreview is set.

if you set the "e.handled=True " in the form, i think the control never gets
it.

Schneider

"John Fiala" <jc********@hot mail.com> wrote in message
news:f2******** *************** ***@posting.goo gle.com...
"Tom" <to*@nospam.com > wrote in message

news:<#r******* *******@TK2MSFT NGP12.phx.gbl>. ..
I must be brain dead or something today, because normally I should be able to figure this out but it just isn't coming to me. Once I am done with the KeyPress event in my control, how can I pass that event (and it's data -
i.e. what key was pressed) back to the host form?

Tom


Do you need to return the sender as well? Otherwise, calling
<control>.OnKey Press(e), where e is the event data object you
intercepted, should do it, right?

John Fiala
jcfiala523-at-hotmail.com
http://www.livejournal.com/users/fiala_tech/

Nov 20 '05 #5

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

Similar topics

12
24182
by: Trevor Fairchild | last post by:
I'm writing a program that is designed for quick navigation using specific buttons on the keyboard. In doing this, I have added a KeyPress event for every control on the form to intercept the key pressed and pass it to a standard subroutine that identifies what action should be taken. Unfortunately, I have a web-browser contol on the form and the webbrowser does not include a KeyPress event. I need some way to intercept keypress and...
8
37093
by: William Ortenberg | last post by:
I'm trying to capture when a user presses a particular key (escape), so I'm coding in the KeyPress event. Yet the code seems be bypassed (breakpoint is never encountered). Should I be coding in a different event? Is this a known issue? FYI, this is happening in both Access 97 and 2000.
0
1351
by: news.gorge.net | last post by:
I want to fire an event when a user presses Control+C when NOT in a situation where that keypress combo would copy something to the clipboard. My current attempt was to override the ProcessDialogKey method in the control, since the KeyPress event doesn't let you know about the Control key presses. In order to not fire my event off when one actually wants to copy something to the clipboard, I put in a call to base.PreocessDialogKey()...
1
6178
by: Rene | last post by:
Hi, I am running is some problems with the KeyPreview and KeyPress events. The KeyPress event is only triggered when there this an focusable control on the form. When all controls are disabled the Form.KeyPress event does not trigger anymore. A way to 'solve' this is to set the focus to the form, but during testing it happens ofter the keypress event is not getting triggered on keys like
10
27866
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? Tim
15
4043
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
3
6858
by: Fia | last post by:
Hi In Visual Basic 6 I could call keypress with an integer of a choosen key. For example I could call a textbox's keypress with the number 13 (for the enter key). But now in Visual Basic .Net I don't know how I shall do to do the same thing. I have tried to send Keys.Numpad8, but then it complains about it cannot convert from Keys to keyEventArgs I have also tried to send the number 8, but then it complains it cannot convert from Integer...
8
36130
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query button on it. If the query returns multiple results, a new window is opened with a grid containing the results. When the user double clicks on the desired row in the grid, I want the first form to populate with the correct data. I don't know how...
2
19292
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
0
8750
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8662
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9244
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7853
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4421
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4679
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.