Cancelling event in event procedure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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.
 
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
 
Adil Akram said:
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
 
I've already tried me.close but it comes up with following error

"Additional information: Cannot call Close() while doing CreateHandle()."
 
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
 
Cor,
As u suggested to correspond privately, tell me your email address. I've
sent mail at your address "(e-mail address removed)" 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.
 
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
 
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.
 
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/d...emwindowsformscontrolclassisdisposedtopic.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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top