By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

Cancelling event in event procedure

P: n/a
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
Share this Question
Share on Google+
12 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.