473,327 Members | 2,103 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,327 software developers and data experts.

Form.Show( ) vs extern ShowWindow

Form form = new Form();

when you call

ShowWindow(form, SW_SHOWNOACTIVATE);

the form disappears the next time the garbage collector is called,
assuming the form variable has gone out of scope. When you call
form.Show() you don't get this behaviour. Why is this? How can you make
ShowWindow( ) behave the same way as Show(), in that the window doesnt
disappear after the Form variable's scope is lost.

Regards
--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Mar 8 '06 #1
2 5507
vooose,

It looks strange that you want to do that, but I believe you have your
reasons.

Here how the control class do it.
1. Create a member of the form of type GCHandle. (formRef)
2. When showing the form call GCHandle.Alloc(this, GCHandleType.Normal).
Save the returned GCHandle object in the variable formRef declared in step 1
for later use.
3. When you are ready to free the form (leave it for garbage collecting)
call formRef.Free();

This works for any objects not only forms or controls.

Other solution would be to declare a static list that will keep references
to all created instances of your form. This might be feasible solution with
forms where you can add the form reference to the list on forms Show and
remove it on Close.
--
HTH
Stoitcho Goutsev (100)
"vooose" <no****@microsoft.com> wrote in message
news:ud**************@TK2MSFTNGP12.phx.gbl...
Form form = new Form();

when you call

ShowWindow(form, SW_SHOWNOACTIVATE);

the form disappears the next time the garbage collector is called,
assuming the form variable has gone out of scope. When you call
form.Show() you don't get this behaviour. Why is this? How can you make
ShowWindow( ) behave the same way as Show(), in that the window doesnt
disappear after the Form variable's scope is lost.

Regards
--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***

Mar 8 '06 #2
Thanks for your reply. Your second solution is the way I was handling
it...I just wasnt very happy with that solution. Option 1 is much better
and implies you know what is really going on! Many Thanks...

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Mar 8 '06 #3

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

Similar topics

19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
5
by: Petec | last post by:
Is there a way to prevent a form from getting focus? Thanks! - Pete
0
by: kurotsuke | last post by:
I'm using the ShowWindow API to show a form (I need it to show the form topmost without focus). My form has no titlebar and should have a height of 16 pixel. When the form is shown it's height is...
6
by: sandy_pt_in | last post by:
Hi, I have modal form which I am showing with some fading effect... (it is like balloon that comes when you receive a mail in the outlook.) But when I show this form, Owner form looses focus. I...
19
by: Oliver Neumann | last post by:
Hello, im new to c# and i got an app with a notifyicon. Now i want to start the app only with the notifyIcon, so that the Main-Form doesnt show up. The form itself is used at the entrance...
4
by: trialproduct2004 | last post by:
Hi all I am new to vb.net application. I am using showdialog property of form to display form. First time it is working properly. But next time it is giving me error that ' object reference not...
4
by: Jawad Rehman | last post by:
Hello EveryBody.... I want to hide Window Form in C#.net.e.g I have an application in which there is one form only,when the application runs,no form will display,but application runs. Just...
4
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I have a situation where I need to display a form in a panel. Everything works great except if the form is maximized and the panel's size changes. In this case the maximized form's bounds do not...
2
by: Rahul | last post by:
Hi everyone, I have the following code and it doesn't give any compilation error, class A { public : A() { } void show()
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.