Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when owner form is closed from an inner control?

Tags:

c#

.net

winforms

How to detect when owner form closes (from a control inside it)?

UPD I need the control to know that it's form is closing, not vice versa

like image 646
user626528 Avatar asked May 30 '11 10:05

user626528


2 Answers

Credits to Fredrik Mörk for this solution:

FindForm().FormClosing += parentForm_FormClosing;
like image 54
Alex Aza Avatar answered Oct 22 '22 22:10

Alex Aza


You should intercept FormClosing event. In FormClosingEventArgs the variable CloseReason will show you why is the form closing. Your best bet is intercepting when this variable equals UserClosing enumerated value.

like image 26
Andrea Pigazzini Avatar answered Oct 22 '22 21:10

Andrea Pigazzini