|
-
May 16th, 2021, 01:03 AM
#1
Thread Starter
Lively Member
Trying to open a form if minimized and close a child
Hoping I explain this properly.
I have a form that opens a menu. With this menu I can open any one of 4 other 'sub programs' within.
The menu Program is called PETS CONSOLE
If I click on the MAIN PROGRAM button on the PETS CONSOLE form it properly opens the MAIN PROGRAM (sub program) parent form with the set default child form preloaded and I can then navigate within the program fine.
If I click DATA ENTRY button on the PETS CONSOLE it opens the Data Entry form (sub program) fine and I can do as I wish... close the Data Entry program and the Main Menu then pops back to the forefront.
My issue is once the MAIN PROGRAM loads I cannot exit and have the Menu program reload. I want to be able to exit the MAIN program and reload the minimized menu form upon closing as I can do with the Data Entry form.
I want to be able to click the "X" on the Parent closing the child and the Parent then check to see if the menu program is minimized and if so, bring it back active otherwise reload the menu form (if someone accidentally closed it for whatever reason). Currently clicking the 'X" (Close) on the main program closes the child fine, closes the parent fine then gives me a 'A new guard page for the stack cannot be created' error and never brings the menu form back from it's minimized state but closes the entire program including the MENU form.
The code I am trying is as follows (the code below is for a 'close button' on the parent form... not the EXIT/CLOSE button as unsure if can use the same code in the FormClosing event.)
Code:
Private Sub NavCloseBtnLoad_Click(sender As Object, e As EventArgs) Handles NavCloseBtnLoad.Click
NavCloseBtnLoad.BackgroundImage = My.Resources.ButtonClk_Red_Trans
Dim Console As Process = Process.GetProcessesByName("PETS Console").FirstOrDefault
If Console IsNot Nothing Then
If IsIconic(Console.MainWindowHandle) Then 'check if the window is minimized. If it is not, then you don't want to restore it, you only need to activate it.
SendMessageW(Console.MainWindowHandle, WM_SYSCOMMAND, SC_RESTORE, 0) 'restore the window from it's minimized state.
Else
AppActivate(Console.Id) 'activate it to bring it to the front of all other windows
End If
Else
Process.GetProcesses("C:\MY PROPER PATH\PETS Console.exe")
End If
Menu1.Close()
End Sub
Please feel free to ask for further and specific clarification if required. I did my best to explain it. Any guidance would be greatly appreciated.
Last edited by K3JAE; May 17th, 2021 at 11:51 AM.
-
May 16th, 2021, 12:06 PM
#2
Re: Trying to open a form if minimized and close a child
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
May 16th, 2021, 12:33 PM
#3
Thread Starter
Lively Member
Re: Trying to open a form if minimized and close a child
 Originally Posted by sapator
That tells me nothing in relation to what I am trying to accomplish. I understand what FormClosing does.
-
May 16th, 2021, 12:42 PM
#4
Re: Trying to open a form if minimized and close a child
You wrote this:
I want to be able to click the "X" on the Parent closing the child and the Parent then check to see if the menu program is minimized and if so, bring it back active otherwise reload the menu.
I tried to respond to this although the explanation is poor. You click the X on the parent closing the child? Explain better.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
May 17th, 2021, 11:50 AM
#5
Thread Starter
Lively Member
Re: Trying to open a form if minimized and close a child
I open a MENU program. I chose a particular sub-program. All programs are packaged into one 'program.' The MENU simply calls a separate program contained within the package. Once chosen the sub program opens and the MENU minimizes. Once I close the sub-program, the Menu then activates and comes back from its minimized state to active on screen.
This works fine with all the other sub-programs except the MAIN program. The MAIN program opens a PARENT form that is a menu for forms within the MAIN to open. All forms for the MAIN then load into the PARENT container. The MAIN program itself runs perfectly fine in stand alone debug mode, but the MENU program is not active during debug. My problem is if I want to close the MAIN program and go back to the MENU to chose another program or simply fully close out. I cannot use the 'X' on the PARENT form of the MAIN to close the main and bring back the MENU program from its minimized state. When I do I get a message 'A new guard page for the stack cannot be created' error and everything closes, to include the MENU program.
Hopefully that clears it up a bit.
Last edited by K3JAE; May 17th, 2021 at 12:02 PM.
Reason: further clarification
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|