7 Answers, 1 is accepted
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
"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.
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
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();}}
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();
}
}
}
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
"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.
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