Dead horse, beat a

  • Thread starter Thread starter Harry Simpson
  • Start date Start date
H

Harry Simpson

I've got two forms. One hides when the second is created and shown. I want
to be able to close processes/threads in the first form from code in the
second form in the overidden OnClosing event in case the user presses the OK
on the form to completely shut the form and app down.

Whenever I try to address the other form i get little to work with and can't
programmatically address controls on the hidden/minimized form. How can i
do that?

TIA
Harry
 
The model of .NET WinForms is that there is a main form and others are
spawned from it. When you need to close the app, you have to close the main
form. You can design your app to fit with that model (rather than try to
make the 2nd form the master at runtime).

If you really want to do what you ask, you could pass the first form to the
second so it has access to the first's data (in case I wasn't clear, I would
not recommend that). So change/add the ctor of the 2nd form to take the
first form as an argument.

Cheers
Daniel
 
Thanks Daniel,

I've read several CF books but I don't think any of them but this in that
context. That makes a lot of sense and is probably why I've had so much
grief between two separate forms!!

In all the examples it's usually one form and coming from Web Forms and
Windows Forms it's a different animal.

Harry
 
Of course there's the other option to run the message pump right in main and
have all Forms be children. It just requires callin Run with no form
instance.

-Chris
 
The parameterless Application.Run is not supported out of the box in the CF
so I guess you are talking about the desktop. In that case, I still go for a
main form but I you could put that down to personal preference.

You may also be talking about using ApplicationEx, in which case you are
right you could do it with that on CF. By the way Chris, have the
ApplicationEx issue with modal dialogs been resolved? That is about the only
thing preventing me from playing with it...

Cheers
Daniel
 
Actually no it's not fixed - I'd not thought much about it until your
mention of it. I've been a bit involved with other things lately, but it
would be a nice addition to have for the SDF 1.3 release.

-Chris
 
So Chris and Daniel,

I really need to only have one form. All other items resembling a "form"
would be panels shown or hidden?
Is this correct?

Harry
 
Not at all. Use one form as the "main" form, a form who'd instance will
always exist and host the application message pump. In my apps it's
typically the first app form shown that isn't a login or splash screen. So
ApplicationEx.Run(mainForm) is the app entry from Main. In that Form's ctor
I do any splashing or authentication.
 
Thanks Chris,

<<So
ApplicationEx.Run(mainForm) is the app entry from Main.>>

You talking about launching the app from Sub Main with
ApplicationEx.Run(frmMain) ?

Right now I have two forms, a frmLogon which contains a pnlLogon with the
logon screen stuff....This form is now also "hosting" the pnlSplash and the
startup form for the app is set to frmLogon. From frmLogon I launch the
frmMain form which is really the meat of the app.

I've got a good deal of "code" on the frmLogon and on the frmMain. It seems
like I'm really going to have to just move the pnlLogon and all the frmLogon
code over to the frmMain.

Would just creating an instance of frmLogon FROM frmMain do the trick? Right
now I'm kinda doing just the opposite.

Thanks
Harry
 
I think I'd change the startup to be frmMain, then in frmMain's ctor create
frmLogon
 
That way when i close frmMain, frmLogon will close completely
too....correct.
But I can really never explicitly close frmLogon from frmMain can i?

I quess this will take care of the loose threads when I close (OK) from the
frmMain now leaving frmLogon kind of out there.....

Appreciate your help Chris

Harry
 
When you're done with frmLogon just close it and set it to null (Nothing)
and it will get disposed of.
 
Chris,

I can beat this horse a little more....may need a new horse!

The deal is I have two Symbol barcode reader controls. One on frmLogon to
scan user pins and one on the frmMain to scan other barcodes. I need to
stop and start these controls. I was starting the frmMain barcode in the
Load event. Same with the other reader in the Logon form. Since I'm
starting the frmMain first, but actually not wanting to start the barcode
reader for this form yet, this presents a problem.

I'm basically showing the Logon form over the top of a visible frmMain after
the changes we've discussed. When I close the frmLogon and issue the
me.dispose, the frmMain form is then visible as expected. How can I start
the barcodereader on frmMain now. I can't access it from frmLogon to turn
it on before i close frmLogon.

Do you see my brain fart?

Harry
 
Two options.

1. Use the same control for both (which is what I'd do). Just pass it from
frmMain to frmLogin
2. Since frmLogin is a member of frmMain, make the control's scope internal
and you can modify it
 
Thanks Chris,

I created object variables for each of the forms in a global module, created
new instance of each for the forms and set the present form to the
respective variable. Then I had a handle to the forms across forms.

I then could do a close and an "is Nothing" and destroy the logon form.
Before this I could also start the barcode control on the main form from the
logon form.

Appreciate your help with this Chris. I was on support this past week and
got a call at 3 am this am so i'm running on empty now...

Thanks
Harry
 
Back
Top