zoukankan      html  css  js  c++  java
  • 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();
            }

    效果图

    image

  • 相关阅读:
    AnyChart图表控件使用指南(四)
    AnyChart图表控件使用指南(五)
    路由器相关
    PHP 实现导出CSV格式文件
    Node.js与Golang使用感受与小结【一】
    Node.js与Golang使用感受与小结【三】JS异步流程控制(序列模式、并发模式、有限并发模式)
    Node.js与Golang使用感受与小结【二】
    js BOM操作
    新建 indexedDB 数据库并插入数据
    vue2项目中引用外部js文件
  • 原文地址:https://www.cnblogs.com/LiuLaoCai/p/3426499.html
Copyright © 2011-2022 走看看