![]() |
|
[C#] Catch form closing event - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Catch form closing event (/showthread.php?tid=5920998) |
Catch form closing event - APΣX - Dec 20, 2018 Hi HF, I'm trying to catch my dashboard.vb form when closing so I can close my parent form (the login system) after doing a bit of research I found that you can't really close the parent form from the child form so what I decided is to just hide the parent form after a successful login and show the child form. The problem I'm having is I'm trying to close the parent form (its still running in the background of the computer but is hidden) by catching when the child form is being exited by the user. Currently, I'm using this code but have no result when closing the child form: Code private void Dashboard_Closing(object sender, System.ComponentModel.CancelEventArgs e)If someone could help me that would be great, or even better suggest a better way to handle all of this, I'm used to VB.NET where parent and child forms don't really exist (from what I know) just regular forms. RE: Catch form closing event - itcorp - Dec 20, 2018 (Dec 20, 2018 07:11 AM)APΣX Wrote: Hi HF, You can do something like this Code private static Dashboard staticInstance = null;usage Code Dashboard.GetInstance().Closing += (b, a) =>RE: Catch form closing event - HFDone - Dec 20, 2018 note that closing event will work just if you close the form with the x button RE: Catch form closing event - n0$f3ratu$ - Dec 20, 2018 You can use a separate thread. It will get the job done. Code private void Form1_FormClosing(object sender, FormClosingEventArgs e)RE: Catch form closing event - BahNahNah - Dec 20, 2018 On the parent form, use ShowDialog insted of .Show() Code this.Hide(); //Hide "parent" formOr a better way in my opinion, in the main form constructor: Code public MainWindow(){or even better, in the Program.cs (or vb equivalent) Code public sttatic void Main(string[] arg){Sorry if the code is botched not in windows atm. RE: Catch form closing event - gigajew - Dec 20, 2018 Use a controller class that controls the appearance and disappearance of forms. Inherit from application context in the controller class and listen to the FormClosed or FormClosing event to decide what comes next RE: Catch form closing event - SlowMehMo - Dec 22, 2018 When using WPF, I usually use shellview but I like to create custom forms and include my own buttons, etc if your able and want to make a stunning user experience then i would suggest making some controls in C# and including that. RE: Catch form closing event - APΣX - Dec 22, 2018 Resolved, thanks @everyone who helped! //Closed |