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

Cancelling event in event procedure

I want to cancel an event from its event procedure on some condition, I know
how to do this in VB6 i.e. by setting cancel=true. Please tell me how can I
do this in VB.net I don't know how to use the eventArgs in VB.net and neither
its help is available in MSDN.

I'm thank full to you in advance.
Nov 21 '05 #1
12 18347
Adil,

It depends on the event. However have a look at the eventarguments if it is
possible than it is normally

e.cancel = true or false.

I hope this helps,

Cor
Nov 21 '05 #2
Thanks for you reply but it didn't solve the problem, I actually want to
cancel the form's Load event. What I want to do is, To stop loading form on
some condition.

Please tell me if this is possible, or if there's any alternative solution
to this problem.

"Cor Ligthert [MVP]" wrote:
Adil,

It depends on the event. However have a look at the eventarguments if it is
possible than it is normally

e.cancel = true or false.

I hope this helps,

Cor

Nov 21 '05 #3
Adil,
Thanks for you reply but it didn't solve the problem, I actually want to
cancel the form's Load event. What I want to do is, To stop loading form
on
some condition.


In the forms load event you can simple place.
me.close

I hope this helps,

Cor
Nov 21 '05 #4
I've already tried me.close but it comes up with following error

"Additional information: Cannot call Close() while doing CreateHandle()."

"Cor Ligthert [MVP]" wrote:
Adil,
Thanks for you reply but it didn't solve the problem, I actually want to
cancel the form's Load event. What I want to do is, To stop loading form
on
some condition.


In the forms load event you can simple place.
me.close

I hope this helps,

Cor

Nov 21 '05 #5
Adil,
I've already tried me.close but it comes up with following error

Your question is Cancellin an event in a event procedure.

I think that it is completly answered.

If you have another problem, than ask that direct, that saves others time.

Just my thought,

Cor
Nov 21 '05 #6
Cor,
As u suggested to correspond privately, tell me your email address. I've
sent mail at your address "no************@planet.nl" but its bounced back.

As told, In load event I tried to close the form but it comes with error
"Additional information: Cannot call Close() while doing CreateHandle()."

I've also tried to call me.Dispose() in constructor but the show method form
caller gives error because object destroyed before show method called.

I've also tried to do this in HandleCreated event but the same error

Please tell me if there's any other event before or after load event that I
can
use safely to cancel form loading, or if u have any other better idea to
tackle this situation please tell me that.
"Cor Ligthert [MVP]" wrote:
Adil,
I've already tried me.close but it comes up with following error

Your question is Cancellin an event in a event procedure.

I think that it is completly answered.

If you have another problem, than ask that direct, that saves others time.

Just my thought,

Cor

Nov 21 '05 #7
"Adil Akram" <Ad*******@discussions.microsoft.com> schrieb
Thanks for you reply but it didn't solve the problem, I actually
want to cancel the form's Load event. What I want to do is, To stop
loading form on some condition.

Please tell me if this is possible, or if there's any alternative
solution to this problem.

Don't show the form if you're not going to show it.
Armin
Nov 21 '05 #8
Adil,

The form class has in fact only one purpose: Showing a form.

Therefore if you don't want to show it use another class to decide if you
want to show it. By instance Armin, Herfried and others use a seperated
module main to start it from.

The best way to get some help in my opinion is to show *some* code by
instance as you have it now in your load form class. Than we maybe
understand what you want to do.

Or even better, explain as well what is the purpose to get that handle.

Cor
"Adil Akram" <Ad*******@discussions.microsoft.com> schreef in bericht
news:2E**********************************@microsof t.com...
Cor,
As u suggested to correspond privately, tell me your email address. I've
sent mail at your address "no************@planet.nl" but its bounced back.

As told, In load event I tried to close the form but it comes with error
"Additional information: Cannot call Close() while doing CreateHandle()."

I've also tried to call me.Dispose() in constructor but the show method
form
caller gives error because object destroyed before show method called.

I've also tried to do this in HandleCreated event but the same error

Please tell me if there's any other event before or after load event that
I
can
use safely to cancel form loading, or if u have any other better idea to
tackle this situation please tell me that.
"Cor Ligthert [MVP]" wrote:
Adil,
> I've already tried me.close but it comes up with following error
>

Your question is Cancellin an event in a event procedure.

I think that it is completly answered.

If you have another problem, than ask that direct, that saves others
time.

Just my thought,

Cor

Nov 21 '05 #9
Armin
Actually I want to prevent opening form if its already opened. I can do this
by writing code at caller but I want some generic code that works for all
forms to prevent a form opening twice.

"Armin Zingler" wrote:
"Adil Akram" <Ad*******@discussions.microsoft.com> schrieb
Thanks for you reply but it didn't solve the problem, I actually
want to cancel the form's Load event. What I want to do is, To stop
loading form on some condition.

Please tell me if this is possible, or if there's any alternative
solution to this problem.

Don't show the form if you're not going to show it.
Armin

Nov 21 '05 #10
Adil,
Actually I want to prevent opening form if its already opened. I can do
this
by writing code at caller but I want some generic code that works for all
forms to prevent a form opening twice.


If you had written this direct than you had got this link and code direct

http://msdn.microsoft.com/library/de...posedtopic.asp

\\\
If Not TheSecondForm.IsDisposed then
dim TheSecondForm as SecondFormClass
TheSecondForm.Show
Else
TheSecondForm.Show
End if
////

This is a complex property normaly not showed or you have to change the
options.

I hope this helps,

Cor

Nov 21 '05 #11
We came across this same problem.

Our workround is to set a module level flag in the load event. Test for
this flag in the Actived event and close the form if the flag is set.
You can close a form from the activated event:

Public Class Form1
....
Private blnAbort as boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If SomeCondition then
blnAbort=True
End If
End Sub

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
If blnAbort then me.Close
End Sub
In message <C1**********************************@microsoft.co m>, Adil
Akram <Ad*******@discussions.microsoft.com> writes
I've already tried me.close but it comes up with following error

"Additional information: Cannot call Close() while doing CreateHandle()."


--
Chris Petchey
Nov 21 '05 #12
Adil,
In addition to the other comments:

The "easiest" way to cancel a Form's Load event is to throw an exception.

Hope this helps
Jay

"Adil Akram" <Ad*******@discussions.microsoft.com> wrote in message
news:25**********************************@microsof t.com...
|I want to cancel an event from its event procedure on some condition, I
know
| how to do this in VB6 i.e. by setting cancel=true. Please tell me how can
I
| do this in VB.net I don't know how to use the eventArgs in VB.net and
neither
| its help is available in MSDN.
|
| I'm thank full to you in advance.
Nov 21 '05 #13

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

Similar topics

0
by: wang xiaoyu | last post by:
Hello,everyone. my program runs well in windows,i use tkSimpleDialog to receive some input,but when i copy my program into Linux RH8.0,entrys in my tkSimpleDialog derived Dialog have a vital...
1
by: Paul THompson | last post by:
I have been working for some time to 1) detect tab and shift tab events 2) control the focus on the basis of these events. I have found that I can do this, but continue to have nagging problems. ...
8
by: InvisibleDuncan | last post by:
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message...
4
by: Newbie | last post by:
Is it possible to set up an event handler or something else so that when *any* link on the page is clicked it 'fires-up', executes some JS and then continues to process the link that was clicked?...
1
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the...
6
by: Steve B. | last post by:
Is it good programming practice to call an event within an event? I'm I creating recursion somehow somewhere? Does an event (e.g. send, e) ever end? I'm sorry, I'm not sure I know what I mean,...
2
by: nford | last post by:
Is there a way to check if an object handles a certain type of event or if the object is hooked up to a certain event handler/call back function? For instance what would be the equivalent syntax...
6
by: MLH | last post by:
I have a form, frmUSPSReturnReceipts, with a control named NotExpectingGreenTickets. The control's Exit event procedure follows: Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer) If...
9
by: pvsundarram | last post by:
hey, i am trying to cancel the keydown event for certain keycodes( for eg:- enter key ).But the cancelling of this event is not happening in firefox. Is there any way to cancel the event in the...
5
by: govolsbaby | last post by:
Not sure how to ask this so I'll try a couple ways. So I have a class with an event... Public Class myClass Public Event SomethingsGoingOn() Private Sub SomethingHappened(ByVal sender As...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.