SandDock 应用示例

时间:2023-03-09 00:30:34
SandDock 应用示例

直接上代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TD.SandDock; namespace SalesClient
{
public partial class frmContainer : Form
{
public static frmContainer Open;
public frmContainer()
{
InitializeComponent();
frmContainer.Open = this;
} Sys.AutoSizeFormClass asc = new SalesClient.Sys.AutoSizeFormClass();
/// <summary>
/// 根据传来的窗口变量参数,打开一个窗口到sandDock(单件模式)
/// </summary>
/// <param name="tempFrm"></param>
public void OpenForm_SandDockSingle(Form tempFrm)
{
if (checkFrm(tempFrm.Name))
{
return;
} TabbedDocument newWin = new TabbedDocument();
newWin.Name = tempFrm.Name;
newWin.Text = tempFrm.Text; newWin.Manager = sandDockManager1;
newWin.CloseAction = DockControlCloseAction.Dispose;
WindowOpenMethod openMethod = (WindowOpenMethod)(2); tempFrm.Load += new EventHandler(tempFrm_Load);
tempFrm.SizeChanged += new EventHandler(tempFrm_SizeChanged); tempFrm.TopLevel = false;
tempFrm.Show(); tempFrm.Parent = newWin;
tempFrm.Dock = DockStyle.Fill;
tempFrm.FormBorderStyle = FormBorderStyle.None;
newWin.Open(openMethod); } private void tempFrm_Load(object sender, EventArgs e)
{
Form frm = sender as Form; asc.Initialize(frm);
} private void tempFrm_SizeChanged(object sender, EventArgs e)
{
Form frm = sender as Form;
asc.ReSize(frm);
} /// <summary>
/// 根据传来的窗口变量参数,打开一个窗口到sandDock(单件模式,关闭以前的)
/// </summary>
/// <param name="tempFrm"></param>
public void OpenForm_SandDockSingleOrClose(Form tempFrm)
{
checkFrmOrClose(tempFrm.Name); TabbedDocument newWin = new TabbedDocument();
newWin.Name = tempFrm.Name;
newWin.Text = tempFrm.Text;
//newWin.AutoScroll = true; newWin.Manager = sandDockManager1;
newWin.CloseAction = DockControlCloseAction.Dispose;
WindowOpenMethod openMethod = (WindowOpenMethod)(2); tempFrm.TopLevel = false;
tempFrm.Parent = newWin;
//tempFrm.Owner = this;
tempFrm.Dock = DockStyle.Fill;
//tempFrm.WindowState = FormWindowState.Maximized;
tempFrm.FormBorderStyle = FormBorderStyle.None;
tempFrm.Show(); newWin.Open(openMethod); }
/// <summary>
/// 根据传来的窗口变量参数,打开一个窗口到sandDock(非单件模式)
/// </summary>
/// <param name="tempFrm"></param>
public void OpenForm_SandDock(Form tempFrm)
{
try
{
TabbedDocument newWin = new TabbedDocument();
newWin.Name = tempFrm.Name;
newWin.Text = tempFrm.Text;
// newWin.AutoScroll = true; newWin.Manager = sandDockManager1;
newWin.CloseAction = DockControlCloseAction.Dispose;
WindowOpenMethod openMethod = (WindowOpenMethod)(2); tempFrm.TopLevel = false;
tempFrm.Parent = newWin;
//tempFrm.Owner = this;
tempFrm.Dock = DockStyle.Fill;
// tempFrm.Left = (newWin.Width - tempFrm.Width) / 2+newWin.Left;
//tempFrm.WindowState = FormWindowState.Maximized;
tempFrm.FormBorderStyle = FormBorderStyle.None;
tempFrm.Show(); newWin.Open(openMethod);
}
catch (Exception)
{
MessageBox.Show("加载窗体(sandDock)出现错误", "窗体加载到sanddock", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
/// <summary>
/// 窗体单件模式
/// </summary>
/// <param name="strFrm"></param>
/// <returns></returns>
private bool checkFrm(string strFrm)
{
bool boolRet = false;
foreach (TabbedDocument aa in sandDockManager1.Documents)
{
if (aa is TabbedDocument && ((TabbedDocument)aa).Name == strFrm)
{
((TabbedDocument)aa).Activate();
boolRet = true;
}
}
return boolRet;
}
/// <summary>
/// 窗体的单件模式(关闭以前窗体)
/// </summary>
/// <param name="strFrmName"></param>
private void checkFrmOrClose(string strFrmName)
{
foreach (TabbedDocument aa in sandDockManager1.Documents)
{
if (aa is TabbedDocument && ((TabbedDocument)aa).Name == strFrmName)
{
((TabbedDocument)aa).Close();
}
}
}
}
}

在FormLoad 里

private void FormMain_Load(object sender, EventArgs e)
{
MethodInvoker mi = new MethodInvoker(InvokeMethod);
this.BeginInvoke(mi);
} private void InvokeMethod()
{
frmContainer sanddock = new frmContainer();
sanddock.TopLevel = false;
sanddock.FormBorderStyle = FormBorderStyle.None;
sanddock.Dock = DockStyle.Fill;
//sanddock.Width = this.spcMain.Panel2.Width;
//sanddock.Height = this.spcMain.Panel2.Height;
sanddock.AutoScroll = true;
this.spcMain.Panel2.Controls.Clear();
this.spcMain.Panel2.Controls.Add(sanddock);
sanddock.Show();
}

效果图

SandDock 应用示例