Hi All,
I created a sub form and in the procedure "Public Sub New()" I'll do some checks.
If the checks are ok the form will be visible, if not, how do I close the window without any error messages and return back to the main form.
Thanks,
AXH
Printable View
Hi All,
I created a sub form and in the procedure "Public Sub New()" I'll do some checks.
If the checks are ok the form will be visible, if not, how do I close the window without any error messages and return back to the main form.
Thanks,
AXH
Hi,Quote:
Originally Posted by ahollaar
Try this;
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub
Wkr,
sparrow1
The window isn't visible yet.
I want to close the window before it will be visible
Hi,
Just on the new event
call the me.close or me.dispose method (as you need)
Hope this helps :wave:
The constructor has nothing whatsoever to do with the form becoming visible. It doesn't make the form visible and it can't the form becoming visible. Once the constructor has completed its then up to the creator whether to call Show or not, which is how the form becomes visible. if your form doesn't want to be shown then it needs to tell its creator not to show it. The most logical way to do this would be to provide a public, read-only, boolean property that indicates whether the checks you performed in the constructor were successful or not, e.g.Your main form would create an instance and then check its Initialised property, only showing the form if it was True.VB Code:
Private ReadOnly _initialised As Boolean = False Public ReadOnly Property Initialise() As Boolean Get Return Me._initialised End Get End Property Public Sub New() '... 'For example. Me._initialised = IO.File.Exists("some critical file") End Sub
Having said that, it would be preferable to perform the checks in the main form before even creating the form instance if that's practical. Why create a form if you're never going to use it?