Posted 12 years ago by Michael Sabo - -privat-
Version: 2.0.0093
Avatar
Hello again,

today I tried a none typically implementation of Docking Windows.

I like to display additional information depends on active control. Therefore I created four Toolwindows and autohide the last three on startup. To my main window (ToolWindow1) I added three text boxes. One for each auto hided Toolwindow. If now one text box gets focus, so the accompanying Toolwindow should be displayed.

The startup code works. But if I press tab or activate the next text box by mouse, the application crash! It seems so it's a recursive problem.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using ActiproSoftware.UIStudio.Dock;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            toolWindow2.AutoHide(ActiproSoftware.Drawing.Sides.Right);
            toolWindow3.AutoHide(ActiproSoftware.Drawing.Sides.Right);
            toolWindow4.AutoHide(ActiproSoftware.Drawing.Sides.Right);
        }

        private void Enter2(object sender, EventArgs e)
        {
            if (toolWindow2.State == ToolWindowState.DockableInsideHost)
                return;
            
            toolWindow3.AutoHide(ActiproSoftware.Drawing.Sides.Right);
            toolWindow4.AutoHide(ActiproSoftware.Drawing.Sides.Right);

            toolWindow2.DockTo(toolWindow1, DockOperationType.RightInner);
        }

        private void Enter3(object sender, EventArgs e)
        {
            if (toolWindow3.State == ToolWindowState.DockableInsideHost)
                return;

            toolWindow2.AutoHide(ActiproSoftware.Drawing.Sides.Right);
            toolWindow4.AutoHide(ActiproSoftware.Drawing.Sides.Right);

            toolWindow3.DockTo(toolWindow1, DockOperationType.RightInner);
        }

        private void Enter4(object sender, EventArgs e)
        {
            if (toolWindow3.State == ToolWindowState.DockableInsideHost)
                return;

            toolWindow2.AutoHide(ActiproSoftware.Drawing.Sides.Right);
            toolWindow3.AutoHide(ActiproSoftware.Drawing.Sides.Right);

            toolWindow4.DockTo(toolWindow1, DockOperationType.RightInner);
        }
    }
}

namespace WindowsApplication1
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.dockManager1 = new ActiproSoftware.UIStudio.Dock.DockManager(this.components);
            this.toolWindow1 = new ActiproSoftware.UIStudio.Dock.ToolWindow();
            this.toolWindowContainer1 = new ActiproSoftware.UIStudio.Dock.ToolWindowContainer();
            this.toolWindow2 = new ActiproSoftware.UIStudio.Dock.ToolWindow();
            this.toolWindowContainer2 = new ActiproSoftware.UIStudio.Dock.ToolWindowContainer();
            this.toolWindow3 = new ActiproSoftware.UIStudio.Dock.ToolWindow();
            this.toolWindowContainer3 = new ActiproSoftware.UIStudio.Dock.ToolWindowContainer();
            this.toolWindow4 = new ActiproSoftware.UIStudio.Dock.ToolWindow();
            this.toolWindowContainer4 = new ActiproSoftware.UIStudio.Dock.ToolWindowContainer();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.textBox3 = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.dockManager1)).BeginInit();
            this.toolWindow1.SuspendLayout();
            this.toolWindowContainer1.SuspendLayout();
            this.toolWindowContainer2.SuspendLayout();
            this.toolWindowContainer3.SuspendLayout();
            this.toolWindowContainer4.SuspendLayout();
            this.SuspendLayout();
            // 
            // dockManager1
            // 
            this.dockManager1.DocumentMdiStyle = ActiproSoftware.UIStudio.Dock.DocumentMdiStyle.ToolWindowInnerFill;
            this.dockManager1.HostContainerControl = this;
            this.dockManager1.ToolWindowsCanAttach = false;
            this.dockManager1.ToolWindowsCanAutoHide = false;
            this.dockManager1.ToolWindowsCanClose = false;
            this.dockManager1.ToolWindowsHaveOptions = false;
            // 
            // toolWindow2
            // 
            this.toolWindow2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.toolWindow2.DockedSize = new System.Drawing.Size(152, 438);
            this.toolWindow2.DockManager = this.dockManager1;
            this.toolWindow2.Location = new System.Drawing.Point(0, 25);
            this.toolWindow2.Name = "toolWindow2";
            this.toolWindow2.Size = new System.Drawing.Size(152, 413);
            this.toolWindow2.TabIndex = 0;
            this.toolWindow2.Text = "toolWindow2";
            // 
            // toolWindow3
            // 
            this.toolWindow3.Dock = System.Windows.Forms.DockStyle.Fill;
            this.toolWindow3.DockedSize = new System.Drawing.Size(107, 438);
            this.toolWindow3.DockManager = this.dockManager1;
            this.toolWindow3.Location = new System.Drawing.Point(4, 25);
            this.toolWindow3.Name = "toolWindow3";
            this.toolWindow3.Size = new System.Drawing.Size(107, 413);
            this.toolWindow3.TabIndex = 0;
            this.toolWindow3.Text = "toolWindow3";
            // 
            // toolWindowContainer2
            // 
            this.toolWindowContainer2.Controls.Add(this.toolWindow2);
            this.toolWindowContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.toolWindowContainer2.DockManager = this.dockManager1;
            this.toolWindowContainer2.Location = new System.Drawing.Point(382, 0);
            this.toolWindowContainer2.Name = "toolWindowContainer2";
            this.toolWindowContainer2.Size = new System.Drawing.Size(152, 438);
            this.toolWindowContainer2.TabIndex = 5;
            // 
            // toolWindowContainer3
            // 
            this.toolWindowContainer3.Controls.Add(this.toolWindow3);
            this.toolWindowContainer3.Dock = System.Windows.Forms.DockStyle.Right;
            this.toolWindowContainer3.DockManager = this.dockManager1;
            this.toolWindowContainer3.Location = new System.Drawing.Point(534, 0);
            this.toolWindowContainer3.Name = "toolWindowContainer3";
            this.toolWindowContainer3.Size = new System.Drawing.Size(111, 438);
            this.toolWindowContainer3.TabIndex = 6;
            // 
            // toolWindow1
            // 
            this.toolWindow1.Controls.Add(this.textBox3);
            this.toolWindow1.Controls.Add(this.textBox2);
            this.toolWindow1.Controls.Add(this.textBox1);
            this.toolWindow1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.toolWindow1.DockedSize = new System.Drawing.Size(378, 200);
            this.toolWindow1.DockManager = this.dockManager1;
            this.toolWindow1.HasTitleBar = ActiproSoftware.ComponentModel.DefaultableBoolean.False;
            this.toolWindow1.Location = new System.Drawing.Point(0, 0);
            this.toolWindow1.Name = "toolWindow1";
            this.toolWindow1.Size = new System.Drawing.Size(378, 438);
            this.toolWindow1.TabIndex = 0;
            this.toolWindow1.Text = "toolWindow1";
            // 
            // textBox3
            // 
            this.textBox3.Location = new System.Drawing.Point(45, 178);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(100, 20);
            this.textBox3.TabIndex = 2;
            this.textBox3.Enter += new System.EventHandler(this.Enter4);
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(45, 148);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(100, 20);
            this.textBox2.TabIndex = 1;
            this.textBox2.Enter += new System.EventHandler(this.Enter3);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(45, 122);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 20);
            this.textBox1.TabIndex = 0;
            this.textBox1.Enter += new System.EventHandler(this.Enter2);
            // 
            // toolWindowContainer1
            // 
            this.toolWindowContainer1.Controls.Add(this.toolWindow1);
            this.toolWindowContainer1.Dock = System.Windows.Forms.DockStyle.Left;
            this.toolWindowContainer1.DockManager = this.dockManager1;
            this.toolWindowContainer1.Location = new System.Drawing.Point(0, 0);
            this.toolWindowContainer1.Name = "toolWindowContainer1";
            this.toolWindowContainer1.Size = new System.Drawing.Size(382, 438);
            this.toolWindowContainer1.TabIndex = 8;
            // 
            // toolWindow4
            // 
            this.toolWindow4.Dock = System.Windows.Forms.DockStyle.Fill;
            this.toolWindow4.DockedSize = new System.Drawing.Size(90, 200);
            this.toolWindow4.DockManager = this.dockManager1;
            this.toolWindow4.Location = new System.Drawing.Point(4, 25);
            this.toolWindow4.Name = "toolWindow4";
            this.toolWindow4.Size = new System.Drawing.Size(90, 413);
            this.toolWindow4.TabIndex = 0;
            this.toolWindow4.Text = "toolWindow4";
            // 
            // toolWindowContainer4
            // 
            this.toolWindowContainer4.Controls.Add(this.toolWindow4);
            this.toolWindowContainer4.Dock = System.Windows.Forms.DockStyle.Right;
            this.toolWindowContainer4.DockManager = this.dockManager1;
            this.toolWindowContainer4.Location = new System.Drawing.Point(645, 0);
            this.toolWindowContainer4.Name = "toolWindowContainer4";
            this.toolWindowContainer4.Size = new System.Drawing.Size(94, 438);
            this.toolWindowContainer4.TabIndex = 9;
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(739, 438);
            this.Controls.Add(this.toolWindowContainer2);
            this.Controls.Add(this.toolWindowContainer3);
            this.Controls.Add(this.toolWindowContainer4);
            this.Controls.Add(this.toolWindowContainer1);
            this.IsMdiContainer = true;
            this.Name = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.dockManager1)).EndInit();
            this.toolWindowContainer2.ResumeLayout(false);
            this.toolWindowContainer3.ResumeLayout(false);
            this.toolWindow1.ResumeLayout(false);
            this.toolWindow1.PerformLayout();
            this.toolWindowContainer1.ResumeLayout(false);
            this.toolWindowContainer4.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private ActiproSoftware.UIStudio.Dock.DockManager dockManager1;
        private ActiproSoftware.UIStudio.Dock.ToolWindow toolWindow1;
        private ActiproSoftware.UIStudio.Dock.ToolWindowContainer toolWindowContainer1;
        private ActiproSoftware.UIStudio.Dock.ToolWindow toolWindow2;
        private ActiproSoftware.UIStudio.Dock.ToolWindowContainer toolWindowContainer2;
        private ActiproSoftware.UIStudio.Dock.ToolWindow toolWindow3;
        private ActiproSoftware.UIStudio.Dock.ToolWindowContainer toolWindowContainer3;
        private ActiproSoftware.UIStudio.Dock.ToolWindow toolWindow4;
        private ActiproSoftware.UIStudio.Dock.ToolWindowContainer toolWindowContainer4;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.TextBox textBox2;

    }
}

Comments (3)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sometimes when adding/removing controls, focus can jump back temporarily to the "main" control. So your Enter event is probably recursively occurring. What I would recommend is adding a form-level boolean variable like "isOpeningToolWindow" and some pseudocode like this for each of your Enter handlers:
if (isOpeningToolWindow)
   return;

isOpeningToolWindow = true;
try {
   // Your code here
}
finally {
   isOpeningToolWindow = false;
}


Actipro Software Support

Posted 12 years ago by Michael Sabo - -privat-
Avatar
I downloaded Docking Windows from Nevron and tried this sample again.
There it works fine.

Michael
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Like I said, it depends on how focus is routed around when controls are added and removed. In your case, focus is probably temporarily being set to the textbox while a tool window control is being removed. If you add the boolean flag as described above, it should work fine.


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.