I have a standard form I use. It inherits from Windows.Forms.F orm. I
usually add a Cancel button the form in the designer. I want to raise the
Cancel button's Click event when the user presses the escape key.
Public Class myStandardForm
Inherits Windows.Forms.F orm
Private WithEvents _btnCancel As Button
Private Sub _Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
MyBase.KeyPrevi ew = True
If Not IsNothing(MyBas e.CancelButton) Then
_btnCancel = MyBase.CancelBu tton
End If
End Sub
Protected Overrides Function ProcessCmdKey(B yRef msg As Message, ByVal
keyData As Keys) As Boolean
If keyData = Keys.Escape Then
' ******* here is where I would like to raise _btnCancel.Clic k
End if
End Function
End Class
Public Class myCustomForm
Inherits myStandardForm
Friend WithEvents btnCancel As System.Windows. Forms.Button
Me.CancelButton = Me.btnExit
Me.Controls.Add (Me.btnExit)
Private Sub btnExit_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnExit.Click
' ************ Sometimes I do special things here.
' ************ I want this code to execute as a result
' ************ of raising the Click event, which happens
' ************ as a result of pressing the Escape key
Me.Close()
End Sub
End Class 3 3426
Take a look at the Button.PerformC lick method.
Ofcourse, you could also do something like this:
Protected Overrides Function ProcessCmdKey( _
ByRef msg As Message, _
ByVal keyData As Keys) As Boolean
If keyData = Keys.Escape Then
ClickProcedure( )
Me.Close()
End if
End Function
Private Sub btnExit_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles btnExit.Click
ClickProcedure( )
Me.Close()
End Sub
Private Sub ClickProcedure( )
' put your special code in here..
End Sub
Ofcourse, this is if you don't need to use the sender and e arguments of the
button click event.
There are probably other ways as well. I guess you can decide what suites
your app best.
hope that helps..
Imran.
"Cary Linkfield" <clinkfield@[NOSPAM]newtondigital.c om> wrote in message
news:%2******** **********@TK2M SFTNGP14.phx.gb l... I have a standard form I use. It inherits from Windows.Forms.F orm. I usually add a Cancel button the form in the designer. I want to raise the Cancel button's Click event when the user presses the escape key.
Public Class myStandardForm Inherits Windows.Forms.F orm Private WithEvents _btnCancel As Button
Private Sub _Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load MyBase.KeyPrevi ew = True If Not IsNothing(MyBas e.CancelButton) Then _btnCancel = MyBase.CancelBu tton End If End Sub
Protected Overrides Function ProcessCmdKey(B yRef msg As Message, ByVal keyData As Keys) As Boolean If keyData = Keys.Escape Then ' ******* here is where I would like to raise _btnCancel.Clic k End if End Function End Class
Public Class myCustomForm Inherits myStandardForm Friend WithEvents btnCancel As System.Windows. Forms.Button Me.CancelButton = Me.btnExit Me.Controls.Add (Me.btnExit)
Private Sub btnExit_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btnExit.Click ' ************ Sometimes I do special things here. ' ************ I want this code to execute as a result ' ************ of raising the Click event, which happens ' ************ as a result of pressing the Escape key Me.Close() End Sub End Class
On Fri, 1 Oct 2004 15:23:54 -0400, Cary Linkfield wrote: I have a standard form I use. It inherits from Windows.Forms.F orm. I usually add a Cancel button the form in the designer. I want to raise the Cancel button's Click event when the user presses the escape key.
Correct me if I'm wrong, but if you set the CancelButton property of the
form to the button in question, I think pressing ESC will cause it to be
clicked.
--
Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
duh! you're right - so much for the ButtonClick method :)
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in
message news:12******** *************** ******@40tude.n et... On Fri, 1 Oct 2004 15:23:54 -0400, Cary Linkfield wrote:
I have a standard form I use. It inherits from Windows.Forms.F orm. I usually add a Cancel button the form in the designer. I want to raise
the Cancel button's Click event when the user presses the escape key.
Correct me if I'm wrong, but if you set the CancelButton property of the form to the button in question, I think pressing ESC will cause it to be clicked.
-- Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and replace certain words in my E-Mail address. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: asr |
last post by:
I've a form with a button on it.
How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.
|
by: (Pete Cresswell) |
last post by:
I've been perusing a "real-life" application and notice that for instance, in a
button's Click() event, they don't write the processing code. Instead, they
raise an event like AddNewRecord and then put the coding that would have been in
the click event in the AddNewRecord event handler.
It seems TB throughout the app, so I'm guessing it's some sort of Best Practice.
Anybody care to explain?
--
PeteCresswell
|
by: Cary Linkfield |
last post by:
I have a standard form I use. It inherits from Windows.Forms.Form. I
usually add a Cancel button the form in the designer. I want to raise the
Cancel button's Click event when the user presses the escape key.
Public Class myStandardForm
Inherits Windows.Forms.Form
Private WithEvents _btnCancel As Button
Private Sub _Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
|
by: Li Weng |
last post by:
Hi,
I have a button (btnSearch) and its Click event sub btnSearch_Click.
Clicking the button will trigger the event. But how do I trigger this event
in code? I tried RaiseEvent btnSearch.Click but there is a syntax error.
Or can I just call btnSearch_Click? But what parameters do I pass in?
Thanks.
Li
|
by: Mauricio Rendon |
last post by:
Hi,
If I have a Label in a Form and need to raise the MouseUp
event on the label to the Form ( Parent Control ), What
must I do ?
Thanks !!!
| |
by: Oney |
last post by:
I want to open a popup window when user click the web server button
control
When user click the button, only OnClik="OpenWindow(12)" is sent
but no event happend no popup opened.After that, user click again
popup window is open. So user must click twice!
So I must raise event twice. How can I do that or do you advice any
solution?
Thanks!
|
by: moondaddy |
last post by:
I wrote my own List class which I use to bind to list controls. this class
inherits CollectionBase and implements IBindingList. This class contains a
list of business classes such as customers for example. In the customer
class I have an event called MyTestEvent and when certain conditions arise,
I want to raise this event which would cause an event to fire in the List
class. How can this be done when I don't actually declare the...
|
by: Michael Maes |
last post by:
Hi,
I want to have a Button.Click event 'raise' a shortcut.
If eg Button1 is Clicked, I want to have a shortcut 'CTRL + F12' activated.
What's the best way to acchieve this.
TIA,
Michael
|
by: Claire |
last post by:
I'm writing an application with custom skinned controls.
I have a text editor form with a rich edit control. Because there's no
toolbuttons in the skinned control set, I have to use normal ones for
Bold/Italic/Underline etc. Because they're normal buttons, they grab focus
from the rich edit. So to prevent losing the caret Ive used the Validating
event to cancel focus loss. This works great.
The application can be run in either terminal or...
|
by: William |
last post by:
Hi
I've created a page with only 'n blank table control on it. When clicking a
button, the table populates with various textboxes and dropdown lists to
make up a complete form. In the last row of the table, a submit button is
added.
Almost everything works fine. The form display, the user fills out the form
and then click Submit. However, the first time the submit button is
clicked, the Click event isn't raised. Just a simple...
|
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...
| |
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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
| |
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |