Visual Studio のツールボックス枠のような、「タプのみ」「外枠張り付き」「浮いた状態」 の3つの状態を持つコントロールを実装する為のフリーのライブラリです。 現在最新バージョンは有償ですが、この有償になる直前のバージョンの 利用方法をまとめた記事です。 ↓最新バージョン 通常ですと、閉じるボタンで非表示になってしまって、メニュー等から再度表示 させる必要があるのがこのコントロールの特徴ですが、Visual Studio のような 多くのツールウインドウを必要としない、一般ユーザのアプレケーション用に チューニングし、非表示にならないコントロールを行っています
関連記事
非常に魅力的なドッキングマネージャですが、なにせ有償になる直前のものですし、 英文ですし、ドキュメントと言える正式なものがありません。 実際、納得のいくインターフェイス構築するのに時間かかりました。 一部オリジナルソース読んで初めて解ったものもありましたし・・・ とにかくこれで使えるでしょう。 1) こちらで E-Mail アドレスを送信 2) ダウンロードリンクが送られてくるのでダウンロード( Magic174AndKrypton.zip ) 3) 解凍して、MagicInstall174.msi のみをインストール ※ 解凍されてプログラムメニューに登録されるだけ ※ dll は、Crownwood Consulting Ltd\Magic Library 1.7.4\Bin 4) VB.NET でプロジェクトを作成 ※ 元々 C# なので、コードを変換するなり読み替えるなりすれば C# でOK 5) MagicLibrary.DLL を参照 6) 以下のコードを貼り付ける Imports Crownwood.Magic.Common Imports Crownwood.Magic.Docking Public Class Form1 Private _dockingManager As DockingManager = Nothing Private _myMemo As Content = Nothing Private hide_control As Boolean = False ' ************************************************************************** ' 初期処理 ' ************************************************************************** Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Me.WebBrowser1.Navigate("http://www.google.co.jp") ' ドッキングマネージャを作成 _dockingManager = New DockingManager(Me, VisualStyle.IDE) ' フォームに貼り付けられたコントロールを追加 _myMemo = _dockingManager.Contents.Add(Me.Panel1, "今日の予定表") ' メモ帳の設定 _myMemo.FullTitle = "メモ : " + DateTime.Today.ToString("d") ' 閉じるボタンを使用しない場合は、Flase を設定 ' ( 閉じるボタンの機能は完全に非表示 ) _myMemo.CloseButton = False ' クリップボタンを表示する _myMemo.HideButton = True ' ドッキング時の初期の横幅( 横にドッキングなので縦は無効 ) _myMemo.AutoHideSize = New Size(270, 270) ' ドッキング中のタブなしの横幅( 横にドッキングなので縦は無効 ) _myMemo.DisplaySize = New Size(270, 270) ' 浮いている状態のサイズ( 浮いている状態のサイズが手動でドッキング時のサイズになる ) _myMemo.FloatingSize = New Size(270, 270) ' メモ帳を表示 _dockingManager.ShowContent(_myMemo) ' メモ帳をたたむ _dockingManager.ToggleContentAutoHide(_myMemo) ' ドッキングされたコントロールが非表示になった時のイベント AddHandler _dockingManager.ContentHidden, AddressOf content_Hidden End Sub ' ************************************************************************** ' 非表示 ' ************************************************************************** Private Sub content_Hidden(ByVal c As Content, ByVal e As System.EventArgs) If Not hide_control Then ' この処理は、浮いている状態からの x ボタンを想定しています ' ( この処理は多少ちらつきます ) c.Docked = True _dockingManager.ShowContent(c) _dockingManager.ToggleContentAutoHide(c) End If End Sub ' ************************************************************************** ' ドッキングしたパネルのメニュー ' ************************************************************************** Private Sub 閉じる_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles 閉じる.Click hide_control = True ' タブ付きかそうでないか If _myMemo.ParentWindowContent.ParentZone Is Nothing Then ' タブあり _dockingManager.HideContent(_myMemo) _dockingManager.ShowContent(_myMemo) Else ' タブなし If _myMemo.Docked Then ' ドッキング中 _dockingManager.ToggleContentAutoHide(_myMemo) Else ' 浮いている状態( この処理は多少ちらつきます ) _myMemo.Docked = True _dockingManager.HideContent(_myMemo) _dockingManager.ShowContent(_myMemo) _dockingManager.ToggleContentAutoHide(_myMemo) End If End If hide_control = False End Sub ' ************************************************************************** ' 状態保存 ' ************************************************************************** Private Sub 状態保存_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles 状態保存.Click _dockingManager.SaveConfigToFile("Config.xml") End Sub End Class 初期状態で、ドッキング位置を変更するには、いったん Contents.Add の後 _dockingManager.AddContentWithState(_myMemo, State.DockRight) のようにして変更します SaveConfigToFile は、現状を XML に保存する処理です。 内容から、プロパティの設定方法が推測できますし、Load すれば 状態の復帰も可能です ( この処理は終了時と起動時以外使わないほうが良いと思いますが ) ToggleContentAutoHide は、状態の切り替えですが、内部では 「タブ付きかそうでないか」が判断基準になっています public virtual bool ToggleContentAutoHide(Content c) { // Content must be visible if (!c.Visible) return false; // Content is not allows to be floating // (if visible then content must have a valiud ParentWindowContent) if (c.ParentWindowContent.State == State.Floating) return false; // Is the content currently in auto hide mode? if (c.ParentWindowContent.ParentZone == null) { // Find the hosting panel for the window content instance AutoHidePanel ahp = AutoHidePanelForState(c.ParentWindowContent.State); // Ask the panel to un-autohide ahp.InvertAutoHideWindowContent(c.ParentWindowContent as WindowContentTabbed); } else { // No, so inform the window content to become auto hidden now InvertAutoHideWindowContent(c.ParentWindowContent); } // Success! return true; }
関連記事
オリジナルサンプルの類では、コントロールを New で作成して実装していますが、 デザイナでドッキングするコントロールのメンテナンが可能なように、デザイナに 貼り付けたものを実装します。 1) Panel 2) MenuStrip 3) RichTextBox ドッキングは、複数可能なので上記セットを追加で作成して _myMemo2 = _dockingManager.Contents.Add(Me.Panel2, "今日の予定表2") のようにして一連の初期処理を実行するようにします。 ( 「閉じる」イベントは個別に必要ですが、処理は共有のメソッドにしたほうが良いでしょう ) <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'フォームがコンポーネントの一覧をクリーンアップするために dispose をオーバーライドします。 <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Windows フォーム デザイナで必要です。 Private components As System.ComponentModel.IContainer 'メモ: 以下のプロシージャは Windows フォーム デザイナで必要です。 'Windows フォーム デザイナを使用して変更できます。 'コード エディタを使って変更しないでください。 <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.RichTextBox1 = New System.Windows.Forms.RichTextBox Me.Panel1 = New System.Windows.Forms.Panel Me.MenuStrip1 = New System.Windows.Forms.MenuStrip Me.閉じる = New System.Windows.Forms.ToolStripMenuItem Me.状態保存 = New System.Windows.Forms.ToolStripMenuItem Me.WebBrowser1 = New System.Windows.Forms.WebBrowser Me.Panel1.SuspendLayout() Me.MenuStrip1.SuspendLayout() Me.SuspendLayout() ' 'RichTextBox1 ' Me.RichTextBox1.Dock = System.Windows.Forms.DockStyle.Fill Me.RichTextBox1.Location = New System.Drawing.Point(0, 24) Me.RichTextBox1.Name = "RichTextBox1" Me.RichTextBox1.Size = New System.Drawing.Size(152, 146) Me.RichTextBox1.TabIndex = 0 Me.RichTextBox1.Text = "" ' 'Panel1 ' Me.Panel1.Controls.Add(Me.RichTextBox1) Me.Panel1.Controls.Add(Me.MenuStrip1) Me.Panel1.Location = New System.Drawing.Point(0, 0) Me.Panel1.Name = "Panel1" Me.Panel1.Size = New System.Drawing.Size(152, 170) Me.Panel1.TabIndex = 1 ' 'MenuStrip1 ' Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.閉じる, Me.状態保存}) Me.MenuStrip1.Location = New System.Drawing.Point(0, 0) Me.MenuStrip1.Name = "MenuStrip1" Me.MenuStrip1.Size = New System.Drawing.Size(152, 24) Me.MenuStrip1.TabIndex = 1 Me.MenuStrip1.Text = "MenuStrip1" ' '閉じる ' Me.閉じる.Font = New System.Drawing.Font("MS ゴシック", 8.25!, System.Drawing.FontStyle.Regular, _ System.Drawing.GraphicsUnit.Point, CType(128, Byte)) Me.閉じる.Name = "閉じる" Me.閉じる.Size = New System.Drawing.Size(28, 20) Me.閉じる.Text = "×" ' '状態保存 ' Me.状態保存.Name = "状態保存" Me.状態保存.Size = New System.Drawing.Size(65, 20) Me.状態保存.Text = "状態保存" ' 'WebBrowser1 ' Me.WebBrowser1.Location = New System.Drawing.Point(211, 60) Me.WebBrowser1.MinimumSize = New System.Drawing.Size(20, 20) Me.WebBrowser1.Name = "WebBrowser1" Me.WebBrowser1.Size = New System.Drawing.Size(328, 307) Me.WebBrowser1.TabIndex = 2 ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(592, 423) Me.Controls.Add(Me.WebBrowser1) Me.Controls.Add(Me.Panel1) Me.MainMenuStrip = Me.MenuStrip1 Me.Name = "Form1" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Form1" Me.Panel1.ResumeLayout(False) Me.Panel1.PerformLayout() Me.MenuStrip1.ResumeLayout(False) Me.MenuStrip1.PerformLayout() Me.ResumeLayout(False) End Sub Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox Friend WithEvents Panel1 As System.Windows.Forms.Panel Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip Friend WithEvents 閉じる As System.Windows.Forms.ToolStripMenuItem Friend WithEvents 状態保存 As System.Windows.Forms.ToolStripMenuItem Friend WithEvents WebBrowser1 As System.Windows.Forms.WebBrowser End Class ライセンスはフリーですが、about ダイアログ等から www.dotnetmagic.com に リンクできるようにして下さいと書かれています。 英文なのであまり自信ありませんので、以下原文 There is no license fee or royalty fee to be paid at any time for using the Magic Library. You are however requested to acknowledge the use of the library and provide a link to our home page www.dotnetmagic.com from the About box of your application. You may include the source code, modified source code, signed assembly or modified built assembly within your own projects for either personal or commercial use but excluding the restrictions outlined below. The following restrictions apply to all parts of the library, including all source code, assemblies, samples and documentation... The above items cannot be sold as is, either individually or together. The above items cannot be modified and then sold as a library component, either individually or together. In other words, if you are using the library to enhance your project then you are fine. If you are trying to gain commercically from the library itself rather than using it to enhance your own work then you are prohibited from its use. If in any doubt they please contact us at license@dotnetmagic.com for a quick determination. |