Troubles Closing Form 
Author Message
 Troubles Closing Form

Hi, Orion

There are some known problems with trying to close a form from a validating
event that are scheduled to be addressed in the next release of VS.Net.  
The easiest work around I can offer, although not especially elegant,
should work for you.  What you can do is delay calling the close method
until after the validation event sequence completes.  Add a disabled timer
to your form with the Interval set to 500.  Add the following code your
project

   Private Sub TextBox1_Validating(ByVal sender As Object, _
   ByVal e As System.ComponentModel.CancelEventArgs) Handles
TextBox1.Validating
      TextBox1.CausesValidation = False
      e.Cancel = True
      Timer1.Enabled = True
   End Sub

   Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
      Timer1.Enabled = False
      Me.Close()
   End Sub

Once the validation sequence is complete, the timer should go off and the
form will be closed.

HTH,

John Eikanger
Microsoft Visual Basic Team

This posting is provided AS IS with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation.  All rights reserved.
--------------------



| Subject: Re: Troubles Closing Form
| Date: Fri, 9 Aug 2002 17:25:34 -0700
| Lines: 115
| X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 207.23.6.71
| Path: cpmsftngxa08!tkmsftngp01!tkmsftngp09
| Xref: cpmsftngxa08 microsoft.public.dotnet.languages.vb:59163
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Thanks, Rob.  That's excellent in that I now understand the DialogResult
| properties better than I did.
|
| Unfortunately, no cigar.  I have precisely this code in my textbox
| validating routine's exception handling code at the appropriate place:
|
| Me.DialogResult = DialogResult.Abort
| Me.Close()
|
| But the thing doesn't close, I assume because it is a modeless form.  The
| odd thing is, too, it sits the focus on the Cancel key, which *never*
occurs
| in code.
|
| For now, I've come up with a half-baked solution to this.  After Me.Close,
| I've inserted:
|
| SendKeys.Send("{Enter}")
|
| I figured, since the focus is sitting on the Cancel key every time this
| happens, I might as well use it!  I really wish I could be more official
| about this, though.  Too often, not having a full understanding of what's
| going on comes back and bites you in the heels.  An answer's gotta be out
| there.  Somebody's got to have solved this once.  Hmph!   ;)
|
| Well, Rob, if anything I've said here stirs any more ideas for you, I'll
| really appreciate it.  All the best,
|
| Orion



Sun, 30 Jan 2005 03:30:32 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Having trouble connecting after closing and opening new form...Help

2. Forms, primary thread closing when closing startup form

3. Form Close Button Does Not Close the Form

4. Open form, close form, open form = disposed object exception

5. Prevent user from closing form using caption close button

6. Closing a form and closing Word

7. Tip : VB.NET Form Won't Close on Me.Close + User Controls

8. Form does not close from the UpperRight X Close button

9. Do I Find or Write the new Form Events (Activated,DeActivated,Closing,Closed)

10. problems using close [x] button when closing forms.

11. window.close closes webbrowser but not the form itself

12. How to prevent user closing a mdi form using the close control button

 

 
Powered by phpBB® Forum Software