473,395 Members | 2,798 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,395 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 18357
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: 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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
jinu1996
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...
0
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...
0
agi2029
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,...

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.