示例#1
0
        /// <summary>
        /// Close the MDI child with the passed handle.
        /// Closing and Closed events will be raised on child.
        /// Close can be cancelled by handling the Closing event Cancel property.
        /// </summary>
        /// <param name="child"></param>
        public void Close(IMDIChild childItem)
        {
            MDIChild child = childItem as MDIChild;

            // sanity check
            if (child == null)
            {
                throw new ArgumentException("Activate child cannot be null");
            }
            if (!mdiChildren.Contains(child))
            {
                throw new InvalidOperationException("Cannot call Close on a child which has not been Show(n)");
            }

            // invoke Closing event
            CancelEventArgs args = new CancelEventArgs();

            child.RaiseClosing(args);
            // check if close has been aborted
            if (args.Cancel)
            {
                return;
            }

            // close/remove
            mdiChildren.Remove(child);
            mdiParent.Items.Remove(child.TabItem);

            // raise Closed event
            child.RaiseClosed();
        }
示例#2
0
        /// <summary>
        /// Show the MDI child with the passed handle.
        /// Opening event will be raised on the child.
        /// If the MDI child is already open (Show called previously),
        /// then it will be Activated.
        /// </summary>
        /// <param name="child"></param>
        public void Show(IMDIChild childItem)
        {
            MDIChild child = childItem as MDIChild;

            // sanity check
            if (child == null)
            {
                throw new ArgumentException("Show child cannot be null");
            }

            // check if mdi child has been shown previously
            if (mdiChildren.Contains(child))
            {
                // activate it
                Activate(child);
                return;
            }

            // add to children
            mdiChildren.Add(child);
            mdiParent.Items.Add(child.TabItem);
            // bring to front
            mdiParent.SelectedItem = child.TabItem;
            // raise opening event
            child.RaiseOpening();
        }
示例#3
0
        /// <summary>
        /// Bring to front the MDI child with the passed handle.
        /// </summary>
        /// <param name="child"></param>
        public void Activate(IMDIChild childItem)
        {
            MDIChild child = childItem as MDIChild;

            // sanity check
            if (child == null)
            {
                throw new ArgumentException("Activate child cannot be null");
            }
            if (!mdiChildren.Contains(child))
            {
                throw new InvalidOperationException("Cannot call Activate on a child which has not been Show(n)");
            }

            // activate
            mdiParent.SelectedItem = child.TabItem;
        }