473,385 Members | 1,707 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,385 software developers and data experts.

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 4504
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.EventArgs)) info and then call
the KeyPress event in the parent?

public class MyControl()

Public Event OnTextBox1KeyPress (ByVal sender as Object, ByVal e As
System.EventArgs)

Private Sub TextBox1_KeyPress (ByVal sender as Object, ByVal e As
System.EventArgs)

'Do something

RaiseEvent OnTextBox1KeyPress (sender,e)

End Sub

End Class

Public Class MyForm

Dim testcontrol as New MyControl

Private Sub testcontrol_KeyPressHandler (ByVal sender as Object, ByVal
e As System.EventArgs) _ Handles testcontrol_OnTextBox1KeyPress

MyForm_KeyPress (sender,e)

End Sub

Private Sub MyForm_KeyPress (ByVal sender as Object, ByVal e As
System.EventArgs) 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****************@TK2MSFTNGP12.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 CausesValidation approach.

Schneider
"Eric Dreksler" <ericd AT accessoneinc DOT com> wrote in message
news:#r*************@TK2MSFTNGP10.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.EventArgs)) info and then call
the KeyPress event in the parent?

public class MyControl()

Public Event OnTextBox1KeyPress (ByVal sender as Object, ByVal e As
System.EventArgs)

Private Sub TextBox1_KeyPress (ByVal sender as Object, ByVal e As
System.EventArgs)

'Do something

RaiseEvent OnTextBox1KeyPress (sender,e)

End Sub

End Class

Public Class MyForm

Dim testcontrol as New MyControl

Private Sub testcontrol_KeyPressHandler (ByVal sender as Object, ByVal e As System.EventArgs) _ Handles testcontrol_OnTextBox1KeyPress

MyForm_KeyPress (sender,e)

End Sub

Private Sub MyForm_KeyPress (ByVal sender as Object, ByVal e As
System.EventArgs) 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****************@TK2MSFTNGP12.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**************@TK2MSFTNGP12.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>.OnKeyPress(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********@hotmail.com> wrote in message
news:f2**************************@posting.google.c om...
"Tom" <to*@nospam.com> wrote in message

news:<#r**************@TK2MSFTNGP12.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>.OnKeyPress(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
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...
8
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...
0
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...
1
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...
10
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? ...
15
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...
3
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...
8
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...
2
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.