This is a migrated thread and some comments may be shown as answers.

Closing the window will close all child windows

7 Answers 1701 Views
TabbedForm
This is a migrated thread and some comments may be shown as answers.
Serg
Top achievements
Rank 1
Veteran
Serg asked on 19 Jul 2020, 10:29 PM
Closing the main window will close all child windows(when dragging tabs). How to fix it? To prevent new windows from closing when closing the main window

7 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Jul 2020, 04:52 AM

Hello, Serg, 

According to the provided information, I suppose that you are experiencing the behavior illustrated in the gif file.

The main RadTabbedForm closes all tabbed windows because its Close button is expected to close the application similar to the close button of other form types - MS Form, RadForm, etc. However, the close button for each RadTabbedFormControlItem is expected to close only the specific item. 

I can suggest you two options: either handle the FormClosing event and cancel it to prevent the application's closing or set the ControlBox property to false.

Feel free to use this approach which suits your requirements best.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

0
Serg
Top achievements
Rank 1
Veteran
answered on 20 Jul 2020, 09:35 AM

"set the ControlBox property to false"

Where can I find this "ControlBox"?

I would like the application to close only after the last window is closed.
And did not close when closing the main "RadTabbedForm" window. 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Jul 2020, 11:39 AM

Hello, Serg, 

The ControlBox property is available at form's level.

Your scenario seems to be similar to the case when multiple forms are opened from the main form. It is expected the application to be closed when the root form is closed. The following StackOverflow thread gives additional information on this default behavior and how it can be avoided by modifying the Program.cs file: https://stackoverflow.com/questions/17953298/c-sharp-application-exits-when-main-form-closes 

I have tested this approach locally on my end and it seems to work as expected. However, as it is noted in the referred thread, it would be necessary to call explicitly Application.Exit when you want to close the entire application. 

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

0
Serg
Top achievements
Rank 1
Veteran
answered on 20 Jul 2020, 08:24 PM

Very good! The code on the link really works! However, now the question arose of how to hang on all created forms when dragging tabs the event - FormClosed

Example:
FormClosed(object sender, FormClosedEventArgs e){if (Application.OpenForms.Count == 0)Application.Exit();}}

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Jul 2020, 07:06 AM

Hello, Serg, 

RadTabbedForm offers several useful events that allow you to detect when a RadTabbedControlElement is being created and when the RadTabbedFormDragDropService creates a new tabbed form. Thus, whenever you click the "+" sign to add a new tab and then drag and drop it outside the main form to create a separate form, you can subscribe to the FormClosed event of each form that may be opened at run time. 

Thus, whenever a form is being closed, you can check whether it is the last opened form and close the entire application. I have prepared a sample code snippet for your reference:
    public partial class RadTabbedForm1 : Telerik.WinControls.UI.RadTabbedForm
    {
        public RadTabbedForm1()
        {
            InitializeComponent();

            this.AllowAero = false;

            this.FormClosed += RadTabbedForm1_FormClosed;
            this.TabbedFormControl.TabbedFormControlElement.ItemDragService.TabbedFormCreating += ItemDragService_TabbedFormCreating;
        }

        private void RadTabbedForm1_FormClosed(object sender, FormClosedEventArgs e)
        {
            CloseApplicationIfLast();
        }

        private void ItemDragService_TabbedFormCreating(object sender, TabbedFormCreatingEventArgs e)
        {
            e.TabbedForm.FormClosed += TabbedForm_FormClosed;
            e.TabbedForm.TabbedFormControlCreating += TabbedForm_TabbedFormControlCreating;
        }

        private void TabbedForm_TabbedFormControlCreating(object sender, TabbedFormControlCreatingEventArgs e)
        {
            e.TabbedFormControl.TabbedFormControlElement.ItemDragService.TabbedFormCreating += ItemDragService_TabbedFormCreating;
        }

        private void TabbedForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            CloseApplicationIfLast(); 
        }

        private void CloseApplicationIfLast()
        {
            if (Application.OpenForms.Count == 0)
            {
                Application.Exit();
            }
        }
    }
Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

0
Serg
Top achievements
Rank 1
Veteran
answered on 21 Jul 2020, 07:17 AM
Thanks for a very good example!
"this.TabbedFormControl.TabbedFormControlElement.ItemDragService.TabbedFormCreating" is what I was looking for and could not find in the documentation to hang the FormClosed event on each form.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Jul 2020, 08:09 AM

Hi, Serg,

I am glad that you find the provided example helpful.

The TabbedFormCreating event is available for the RadTabbedFormDragDropService. Additional information about the service is available in the online documentation: https://docs.telerik.com/devtools/winforms/controls/forms-and-dialogs/tabbedform/features/drag-and-drop 

If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Tags
TabbedForm
Asked by
Serg
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Serg
Top achievements
Rank 1
Veteran
Share this question
or