473,395 Members | 1,383 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.

Closing an opening window

I need to:
a) Close a windows form from within the form's code itself
b) It must be able to occur after the form's constructor function is called
(like from another function that's called before .Show())
c) It must be able to occur before the form is actually viewable.

It's for security purposes.

If I add it to load, I get an error that you can't call close() or dispose()
while creating the window handle. I also tried doing it in the handlecreated
event for that reason, but I get the same error.

Any ideas (other than not calling .Show())?
Nov 16 '05 #1
6 1404
I would like to know that as well but I found a suitable work around in my
case that may be of help. I created a form property that was set after the
InitializeComponent() and tested it's value in the LOAD() of the form. If
it wasn't what I wanted it would close the form before anyone could use it.
private void MainForm_Load(object sender, System.EventArgs e)

{

if (this.isLoggedIn == true)

{

}

else

{

this.Close() ;

}
}
--
Andrew J. Kelly SQL MVP
"John Smith" <js@no.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I need to:
a) Close a windows form from within the form's code itself
b) It must be able to occur after the form's constructor function is
called
(like from another function that's called before .Show())
c) It must be able to occur before the form is actually viewable.

It's for security purposes.

If I add it to load, I get an error that you can't call close() or
dispose()
while creating the window handle. I also tried doing it in the
handlecreated
event for that reason, but I get the same error.

Any ideas (other than not calling .Show())?

Nov 16 '05 #2
See, but when I do that, I get the error that you can't close the form while
creating the window handle. I can't call close or dispose in load without
getting the error.
"Andrew J. Kelly" <sq************@shadhawk.com> wrote in message
news:e1**************@TK2MSFTNGP14.phx.gbl...
I would like to know that as well but I found a suitable work around in my
case that may be of help. I created a form property that was set after the
InitializeComponent() and tested it's value in the LOAD() of the form. If
it wasn't what I wanted it would close the form before anyone could use it.

private void MainForm_Load(object sender, System.EventArgs e)

{

if (this.isLoggedIn == true)

{

}

else

{

this.Close() ;

}
}
--
Andrew J. Kelly SQL MVP
"John Smith" <js@no.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I need to:
a) Close a windows form from within the form's code itself
b) It must be able to occur after the form's constructor function is
called
(like from another function that's called before .Show())
c) It must be able to occur before the form is actually viewable.

It's for security purposes.

If I add it to load, I get an error that you can't call close() or
dispose()
while creating the window handle. I also tried doing it in the
handlecreated
event for that reason, but I get the same error.

Any ideas (other than not calling .Show())?


Nov 16 '05 #3
Thats odd, it works for me. I copied straight from my form that I am
currently messing with. I will take a further look and see if anything
comes to mind.

--
Andrew J. Kelly SQL MVP
"John Smith" <js@no.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
See, but when I do that, I get the error that you can't close the form
while
creating the window handle. I can't call close or dispose in load without
getting the error.
"Andrew J. Kelly" <sq************@shadhawk.com> wrote in message
news:e1**************@TK2MSFTNGP14.phx.gbl...
I would like to know that as well but I found a suitable work around in
my
case that may be of help. I created a form property that was set after
the
InitializeComponent() and tested it's value in the LOAD() of the form.
If
it wasn't what I wanted it would close the form before anyone could use

it.


private void MainForm_Load(object sender, System.EventArgs e)

{

if (this.isLoggedIn == true)

{

}

else

{

this.Close() ;

}
}
--
Andrew J. Kelly SQL MVP
"John Smith" <js@no.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
>I need to:
> a) Close a windows form from within the form's code itself
> b) It must be able to occur after the form's constructor function is
> called
> (like from another function that's called before .Show())
> c) It must be able to occur before the form is actually viewable.
>
> It's for security purposes.
>
> If I add it to load, I get an error that you can't call close() or
> dispose()
> while creating the window handle. I also tried doing it in the
> handlecreated
> event for that reason, but I get the same error.
>
> Any ideas (other than not calling .Show())?
>
>



Nov 16 '05 #4
I am not up yet on the way C# handles inheritance but in my case my form was
based directly on the Form class. Is yours based on a subclass? If so make
sure the Load() of the base class (or what ever it's called din C#) is
called before you issue the Close().
--
Andrew J. Kelly SQL MVP
"Andrew J. Kelly" <sq************@shadhawk.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thats odd, it works for me. I copied straight from my form that I am
currently messing with. I will take a further look and see if anything
comes to mind.

--
Andrew J. Kelly SQL MVP
"John Smith" <js@no.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
See, but when I do that, I get the error that you can't close the form
while
creating the window handle. I can't call close or dispose in load
without
getting the error.
"Andrew J. Kelly" <sq************@shadhawk.com> wrote in message
news:e1**************@TK2MSFTNGP14.phx.gbl...
I would like to know that as well but I found a suitable work around in
my
case that may be of help. I created a form property that was set after
the
InitializeComponent() and tested it's value in the LOAD() of the form.
If
it wasn't what I wanted it would close the form before anyone could use

it.


private void MainForm_Load(object sender, System.EventArgs e)

{

if (this.isLoggedIn == true)

{

}

else

{

this.Close() ;

}
}
--
Andrew J. Kelly SQL MVP
"John Smith" <js@no.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
>I need to:
> a) Close a windows form from within the form's code itself
> b) It must be able to occur after the form's constructor function is
> called
> (like from another function that's called before .Show())
> c) It must be able to occur before the form is actually viewable.
>
> It's for security purposes.
>
> If I add it to load, I get an error that you can't call close() or
> dispose()
> while creating the window handle. I also tried doing it in the
> handlecreated
> event for that reason, but I get the same error.
>
> Any ideas (other than not calling .Show())?
>
>



Nov 16 '05 #5
Cant you just create a public procedure in your form. Then, instead of
calling
..show(), call it. For instance:

private class Form1 : Form
{
....

public void CheckThenShow()
{
//check to see if person is allowed to see form
if (Allowed)
this.show();
}
....
}
"John Smith" wrote:
I need to:
a) Close a windows form from within the form's code itself
b) It must be able to occur after the form's constructor function is called
(like from another function that's called before .Show())
c) It must be able to occur before the form is actually viewable.

It's for security purposes.

If I add it to load, I get an error that you can't call close() or dispose()
while creating the window handle. I also tried doing it in the handlecreated
event for that reason, but I get the same error.

Any ideas (other than not calling .Show())?

Nov 16 '05 #6
Nevermind. I reread your post and saw that you did not want to call a
different method than .show()

"landagen" wrote:
Cant you just create a public procedure in your form. Then, instead of
calling
.show(), call it. For instance:

private class Form1 : Form
{
...

public void CheckThenShow()
{
//check to see if person is allowed to see form
if (Allowed)
this.show();
}
...
}
"John Smith" wrote:
I need to:
a) Close a windows form from within the form's code itself
b) It must be able to occur after the form's constructor function is called
(like from another function that's called before .Show())
c) It must be able to occur before the form is actually viewable.

It's for security purposes.

If I add it to load, I get an error that you can't call close() or dispose()
while creating the window handle. I also tried doing it in the handlecreated
event for that reason, but I get the same error.

Any ideas (other than not calling .Show())?

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jawahar Rajan | last post by:
All, I have a printer friendly page that is opened when a user clicks a link on my page to get the printer friendly version, How ever when they close out the printer friendly version and return to...
2
by: gokul | last post by:
Hi all, Iam using mozilla firebird. I have three popups displayed at one point of time...if I close one the other two goes hidden....could you please suggest me the reason for this behaviour and...
1
by: MJEASSOC | last post by:
I need some help with closing a popup window. I'm making an online portfolio, that has one base page with text and thumbnails. When a user clicks on a thumb, a new window opens containing a larger...
4
by: bbass | last post by:
thanks to all that replyied to my previous post with the following code in question: <a href="merc.htm" target="_new_merc" onfocusout=window.close class="left_link"> i understand that the...
3
by: Greg | last post by:
On my report I want to have an opening balance signifying all transactions up to the month selected and detailed transactions for the month selected and then a closing blance. I'm perpelexed...
3
by: Alvo von Cossel I | last post by:
hi, i have a working console app. however, it closes as soon as it opens. i know that it works because i can just about read it. how do i stop it from closing straight after opening? -- Alvo...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
3
by: sravan_reddy001 | last post by:
i want to prevent a form from closing.. to do this i want to handle the formClosing or FormClosed events. from here i want to prevent the form from closing. New instance of same form should...
11
by: Simon van Beek | last post by:
Dear reader, By opening an application I get always the main Access window with the closing cross in the above right corner. Is there a possibility to make this closing cross invisible? ...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.