0

I've got an MDI form with child forms that I'd like to refactor to a single form with a tab control containing child controls, in order to move away from MDI clunkiness.

When looking at converting the child forms into child controls (or usercontrols), I do see that I'd lose the FormClosing event, which some of the child forms use.

I can override Dispose to handle some of the functionality, but in some cases I'd like to cancel the closing event. Also, I'd like this event to be called before the control is closed even when the form it's on isn't closing, so wiring the control to the form's closing event isn't an option.

Is there a clean way of reproducing the FormClosing event in the control class, or should I keep the child forms as Forms when I add them to the tab control?

Edit: To be a little more clear, I'm looking for a way to raise something like ControlClosing on a user control before it's closed (not necessarily when the host form is closed) in order to prompt the user if they wish to save changes to their data, and allow the user to select the standard Yes / No / Cancel.

I'm not looking to override the closing of the form that hosts the control.

Community
  • 1
  • 1
MCattle
  • 2,897
  • 2
  • 38
  • 54
  • Ended up staying with MDI forms and using the Infragistics TabbedMDIManager control to give the nice tabbed interface, but Nick's answer was the way I'd go if I decided to create the tabbed interface manually with child controls. – MCattle Apr 26 '12 at 23:10

2 Answers2

0

Try ParentChanged, or possibly VisibleChanged.

Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
0

As long as you create your child form in the Tab Control (I assume you put one child form for each TagPage), you can remove the whole TabPage or just the object in the TabPage to dispose your child form

TabControl1.TabPages.Remove(TabPage1)

or

TabPage1.Controls.Remove(ChildForm)
Nick
  • 1,128
  • 7
  • 12
  • I was hoping to have something internal to the child control class (actually the base class from which my child form controls derive), but this may be the point at which I might have to ask the child control if it has unsaved data. – MCattle Apr 26 '12 at 06:44
  • Then you may need something like **`Me.Parent.Controls.Remove(Me)`** – Nick Apr 26 '12 at 06:50