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

DocumentCloseButton Event?

4 Answers 144 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 16 Jan 2012, 08:32 PM
I'm using the Q3 2009 Telerik controls (2009.3.9.1203) and have a scenario where I populate a RadDock initially and allow the user to add/remove additional DocumentWindows. When the user closes a DocumentWindow through the 'X' next to each tab (the button added to the title by setting ShowDocumentCloseButton to true), I'd like a prompt to come up to warn the user that they'd lose their data. However, the application at points removes and adds DocumentWindows to the same RadDock, and I don't want the prompt to appear in those scenarios.

Right now I am hooked into the DockWindowClosing event. Through debugging I haven't found any information in the sender or event args that specify where the event was called from. In this case, when the program has to programmatically remove forms the user gets the prompt I created. I figure the best way to go about this is to ditch using the DockWindowClosing event, and try to hook into the Click event of that DocumentCloseButton.

Is this at all possible? Is there another way to achieve what I'd like to do?

4 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 19 Jan 2012, 12:46 PM
Hi Eric,

The DockWindowClosing event is the most suitable solution for your application. You can get the DockWindow and validate some data or show a message box to the user. Here is a simple example where MdiChildren Forms are added using AutoDetectMdiChildren and the close logic validates the hosted form object:

void radDock1_DockWindowClosing(object sender, DockWindowCancelEventArgs e)
{
    HostWindow hostWindow = e.DockWindow as HostWindow;
    if (hostWindow != null)
    {
        Form form = hostWindow.Content as Form;
        e.Cancel = form.Validate();
    }
}

I hope this helps.

All the best,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Eric
Top achievements
Rank 1
answered on 19 Jan 2012, 03:31 PM
Unfortuantely I've gotten to this point. However, if the user decides to change the file we need a way to remove the documents from the DocumentManager without setting off any user prompts. We only want to prompt if the user clicks the close button. There will be other automated events (such as closing the application or changing the file which reloads the UI) where we don't want this prompt to appear.
0
Julian Benkov
Telerik team
answered on 24 Jan 2012, 02:27 PM
Hi Eric,

In this case you can cancel the closing operation and manually handle the Click event. Please consider the sample below:

using System;
using System.Windows.Forms;
using Telerik.WinControls.UI.Docking;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            RadDock radDock1 = new RadDock();
            radDock1.Dock = DockStyle.Fill;
            this.Controls.Add(radDock1);
 
            radDock1.ShowDocumentCloseButton = true;
            radDock1.DockWindowClosing += new DockWindowCancelEventHandler(radDock1_DockWindowClosing);
            ToolWindow toolWindow = new ToolWindow();
            radDock1.DockWindow(toolWindow, DockPosition.Right);
 
            DocumentWindow document = new DocumentWindow();
            document.DocumentButtons = DocumentStripButtons.None;
            radDock1.AddDocument(document);
            document.TabStripItem.CloseButton.Click += new EventHandler(CloseButton_Click);
 
            DocumentWindow document2 = new DocumentWindow();
            document2.DocumentButtons = DocumentStripButtons.None;
            radDock1.AddDocument(document2);
            document2.TabStripItem.CloseButton.Click += new EventHandler(CloseButton_Click);
 
            DocumentWindow document3 = new DocumentWindow();
            radDock1.AddDocument(document3);
            document3.TabStripItem.CloseButton.Click += new EventHandler(CloseButton_Click);
        }
 
        void radDock1_DockWindowClosing(object sender, DockWindowCancelEventArgs e)
        {
            if (e.DockWindow is HostWindow || e.DockWindow is DocumentWindow)
            {
                e.Cancel = true;
            }
        }
 
        void CloseButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Close Click");
        }
    }
}

I hope this helps. 

Regards,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Eric
Top achievements
Rank 1
answered on 24 Jan 2012, 11:40 PM
Thanks, this did the trick.
Tags
Dock
Asked by
Eric
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Eric
Top achievements
Rank 1
Share this question
or