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

Keypressed event of a form

Hi guys,

Im new to dot net and wondering how i could remake the same way i was in
vb6, capture all keypress whitin a form,

per exemple i was on the form looking for some keypress

privete sub form_keypressed(keyascii as integer)
if keyascii = 13 then 'for the enter key
call button_click
end if
end sub

what i got so far in vb .net is :

Private Sub FrmMain_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = "P" Or e.KeyChar = "p" Then

e.Handled = True

Call BtmProduit_Click(sender, e)

End If

end sub

which is not working and dosent fire any event at all, so after looking the
forum and internet, ive found nothing that was working,

Thanks a lot in advance !

Him
Nov 21 '05 #1
13 6052
Himselff wrote:
Hi guys,

Im new to dot net and wondering how i could remake the same way i was in
vb6, capture all keypress whitin a form,

per exemple i was on the form looking for some keypress

privete sub form_keypressed(keyascii as integer)
if keyascii = 13 then 'for the enter key
call button_click
end if
end sub

what i got so far in vb .net is :

Private Sub FrmMain_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = "P" Or e.KeyChar = "p" Then

e.Handled = True

Call BtmProduit_Click(sender, e)

End If

end sub

which is not working and dosent fire any event at all, so after looking the
forum and internet, ive found nothing that was working,

Thanks a lot in advance !

Him


Did you set the keypreview setting of the form to true?
Also I'd change your if to something like:

If UCase(e.KeyChar)="P" then

--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #2
Ive Read about the keypreview but i cannot find anything , is that a form
attribute ? like form.keypreview ?

Thanks !

Him
"C-Services Holland b.v." <cs*@REMOVEcsh4u.nl> a écrit dans le message de
news: 3o********************@zeelandnet.nl...
Himselff wrote:
Hi guys,

Im new to dot net and wondering how i could remake the same way i was in
vb6, capture all keypress whitin a form,

per exemple i was on the form looking for some keypress

privete sub form_keypressed(keyascii as integer)
if keyascii = 13 then 'for the enter key
call button_click
end if
end sub

what i got so far in vb .net is :

Private Sub FrmMain_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = "P" Or e.KeyChar = "p" Then

e.Handled = True

Call BtmProduit_Click(sender, e)

End If

end sub

which is not working and dosent fire any event at all, so after looking
the forum and internet, ive found nothing that was working,

Thanks a lot in advance !

Him


Did you set the keypreview setting of the form to true?
Also I'd change your if to something like:

If UCase(e.KeyChar)="P" then

--
Rinze van Huizen
C-Services Holland b.v.

Nov 21 '05 #3
set the form keypreview property to true to capture all keypresses on form,
even if they're inside a textbox, use keydown to check. fe

if e.keycode = keys.enter then
'do stuff
end if

hth Peter

"Himselff" <flamontagne@no_spam.polyform.com> wrote in message
news:ul**************@TK2MSFTNGP09.phx.gbl...
Hi guys,

Im new to dot net and wondering how i could remake the same way i was in
vb6, capture all keypress whitin a form,

per exemple i was on the form looking for some keypress

privete sub form_keypressed(keyascii as integer)
if keyascii = 13 then 'for the enter key
call button_click
end if
end sub

what i got so far in vb .net is :

Private Sub FrmMain_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = "P" Or e.KeyChar = "p" Then

e.Handled = True

Call BtmProduit_Click(sender, e)

End If

end sub

which is not working and dosent fire any event at all, so after looking the forum and internet, ive found nothing that was working,

Thanks a lot in advance !

Him

Nov 21 '05 #4
Thats exactly what ive read but where u get the keypreview from ?

when i write form1.keypreview it says that i have an error, like :
keypreview is not a member of form1,

any clue ?

Thnaks !
"Peter Proost" <pp*****@nospam.hotmail.com> a écrit dans le message de news:
%2****************@TK2MSFTNGP09.phx.gbl...
set the form keypreview property to true to capture all keypresses on
form,
even if they're inside a textbox, use keydown to check. fe

if e.keycode = keys.enter then
'do stuff
end if

hth Peter

"Himselff" <flamontagne@no_spam.polyform.com> wrote in message
news:ul**************@TK2MSFTNGP09.phx.gbl...
Hi guys,

Im new to dot net and wondering how i could remake the same way i was in
vb6, capture all keypress whitin a form,

per exemple i was on the form looking for some keypress

privete sub form_keypressed(keyascii as integer)
if keyascii = 13 then 'for the enter key
call button_click
end if
end sub

what i got so far in vb .net is :

Private Sub FrmMain_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = "P" Or e.KeyChar = "p" Then

e.Handled = True

Call BtmProduit_Click(sender, e)

End If

end sub

which is not working and dosent fire any event at all, so after looking

the
forum and internet, ive found nothing that was working,

Thanks a lot in advance !

Him


Nov 21 '05 #5
Himselff,

In VBNet you can make an array of the controls that you want to use and with
that tell exactly controls should have that event. Keypress is an event from
control so I think you cannot come in much problems with that. (I thought
that there are controls where that event is hidden so do not think that it
directly works everywhere).

All is typed in this messages not tested so watch errors or typos.

You can make that array like this
\\\
Dim mykeypressctrs as control() = new control() {textbox1, richtextbox1,
textbox2, etc}
///
And than something as this to add the handlers to that.
\\\
For Each ctr As Control In mykeypressctrs
AddHandler ctr.keypress, AddressOf FrmMain_KeyPress
Next
///

I hope this helps?

Cor
Nov 21 '05 #6
Himselff wrote:
Ive Read about the keypreview but i cannot find anything , is that a form
attribute ? like form.keypreview ?

Thanks !

Him


If you select your form in the designer, one of the properties is
keypreview.

--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #7
That part dont realy apply to me cause i want to emulate button click from a
keypress event so all event are handle from form event handler !

I understand the point by the way and i take all in note in case i need it
someday ,

thanks for the info !

"Cor Ligthert" <no************@planet.nl> a écrit dans le message de news:
Ob**************@tk2msftngp13.phx.gbl...
Himselff,

In VBNet you can make an array of the controls that you want to use and
with that tell exactly controls should have that event. Keypress is an
event from control so I think you cannot come in much problems with that.
(I thought that there are controls where that event is hidden so do not
think that it directly works everywhere).

All is typed in this messages not tested so watch errors or typos.

You can make that array like this
\\\
Dim mykeypressctrs as control() = new control() {textbox1, richtextbox1,
textbox2, etc}
///
And than something as this to add the handlers to that.
\\\
For Each ctr As Control In mykeypressctrs
AddHandler ctr.keypress, AddressOf FrmMain_KeyPress
Next
///

I hope this helps?

Cor

Nov 21 '05 #8
When u say newby remember himselff =)

Ive been trough all option of the form in designer and i dont find anything
that look like keypreview, mabe im missing something here ?

Thanks !
"C-Services Holland b.v." <cs*@REMOVEcsh4u.nl> a écrit dans le message de
news: V4********************@zeelandnet.nl...
Himselff wrote:
Ive Read about the keypreview but i cannot find anything , is that a form
attribute ? like form.keypreview ?

Thanks !

Him


If you select your form in the designer, one of the properties is
keypreview.

--
Rinze van Huizen
C-Services Holland b.v.

Nov 21 '05 #9
By the way i just forget one detail, im developing for a pocket PC windows
CE .net mabe its the reason i dont have the keypreview on my form ?

Him
"Himselff" <flamontagne@no_spam.polyform.com> a écrit dans le message de
news: eb****************@tk2msftngp13.phx.gbl...
When u say newby remember himselff =)

Ive been trough all option of the form in designer and i dont find
anything that look like keypreview, mabe im missing something here ?

Thanks !
"C-Services Holland b.v." <cs*@REMOVEcsh4u.nl> a écrit dans le message de
news: V4********************@zeelandnet.nl...
Himselff wrote:
Ive Read about the keypreview but i cannot find anything , is that a
form attribute ? like form.keypreview ?

Thanks !

Him


If you select your form in the designer, one of the properties is
keypreview.

--
Rinze van Huizen
C-Services Holland b.v.


Nov 21 '05 #10
If you can't see the KeyPreview property, it could be that you have a control
with the focus. Click on the form background to make sure that you can see
the property!

HTH

Nigel
Nov 21 '05 #11
I realy dont have that option, no control got the focus, even when i type in
my code frmmain.something it dont show up, as i said previously , is there
any chance that the fact that im developing a project for pocket pc dont
allow any keypress event handler ?

Thanks !

"Nigel Armstrong" <Ni************@discussions.microsoft.com> a écrit dans le
message de news: 41**********************************@microsoft.com...
If you can't see the KeyPreview property, it could be that you have a
control
with the focus. Click on the form background to make sure that you can see
the property!

HTH

Nigel

Nov 21 '05 #12

"Himselff" <flamontagne@no_spam.polyform.com> wrote
By the way i just forget one detail, im developing for a pocket PC windows
CE .net mabe its the reason i dont have the keypreview on my form ?


Yes, that is the reason. The PPC has an OnScreen Keyboard to allow
users to enter text into textboxes. Its not the same model as the Windows
Forms....

LFS
Nov 21 '05 #13

"Himselff" <flamontagne@no_spam.polyform.com> wrote
By the way i just forget one detail, im developing for a pocket PC windows
CE .net mabe its the reason i dont have the keypreview on my form ?


Yes, that is the reason. The PPC has an OnScreen Keyboard to allow
users to enter text into textboxes. Its not the same model as the Windows
Forms....

LFS
Nov 21 '05 #14

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

Similar topics

0
by: James Ng | last post by:
I have posted this to the Citrix Developers' forum and have not heard anything yet. So I'd like to see if any other Java developers have experience this problem with their Java application in a...
4
by: Chris | last post by:
Hi, I followed the the aricle http://support.microsoft.com/default.aspx?scid=kb;en-us;321525 and was able to execute a dts package in vb.net. I replaced all the "Console.WriteLine" with "msgbox"....
0
by: Chris | last post by:
Hi, I would like to reise events when an error occur in my component and pass the error message to clients consuming the component. example Public Function WillFuelContinueToRasie()
0
by: chenedor | last post by:
hi guys i ve got a window form to display a message "loading please wait" and to do a long and big loop. my problem is i do not know where to put my big loop ? if i put it in the load event,...
2
by: active | last post by:
I have a picturebox usercontrol sitting on a usercontrol. I need a KeyPress event in the PictureBox. I suppose I could have a property in the pictureBox that is accessed by a call in a...
9
by: Rob | last post by:
When a custom control is used within a form, that control does not get events directly. I've run into this a couple times with both mouse and keyboard events. Ex: A custom control inherits from...
1
by: JDeats | last post by:
If you create a new C# Windows Application project in Visual Studio.NET 2003 or 2005 and proceed to. 1. Make default form size 800x600 2. Drop a CheckBoxList control and dock it to the left 3....
0
by: Luzuko | last post by:
Hi mates, I have written the code below on VB 2005 to try and restrict input on a textbox. This code works very well on VB 2005 and its controls. However my project's User interface...
2
by: GS | last post by:
I was trying to catch the control enter key sequence of a combo box in the keydown event, but I failed to se anything like control enter, neither Did I find in keypresssed event I tried google...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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,...

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.