Previous topicNext topic
Help > 开发指南 > SanMuGrid平台编程 > 扩展示例 >
自定义桌面

本平台是可以让大家自定义自己的界面布局的。这里就用一个Demo介绍一下如何自定义自己的界面布局。

第一步:创建界面布局的窗体。窗体中必须包含一个C1DockingTab控件,默认包含一个页面,标题为“主页”。下一步写自定义界面布局的类需要用。其他的布局功能自己随意发挥。

界面设计好之后,自己写好界面加载的逻辑。如果界面中包含执行系统菜单的功能的话,可以利用AutoMenu.MenuClickForOpenForms方法。

 Vb.Net
Imports System
Imports System.Text
Imports System.IO
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing.Text
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Imports System.Collections.Specialized
Imports System.Windows.Forms
Imports System.Reflection
Imports Microsoft.CSharp
Imports Microsoft.VisualBasic
Imports sanMuSoft.Utility
Imports System.Linq
Imports System.Threading
Imports System.Threading.Tasks
Imports System.Net.Http
Imports C1.C1Excel
Imports C1.C1Zip
Imports C1.Win.C1Command
Imports C1.Win.C1FlexGrid
Imports C1.Win.C1Input
Imports C1.Win.C1Ribbon
Imports C1.Win.C1Themes
Imports sanMuSoft.CS.Framework
Imports sanMuSoft.CS.Framework.Editor
Imports sanMuSoft.CS.Framework.FormDesigner
Imports sanMuSoft.CS.Framework.DropDownForms
Imports sanMuSoft.CS.WinForm
Imports sanMuSoft.CS.WinForm.Editor
Imports sanMuSoft.CS.WinForm.Controls
Imports sanMuSoft.CS.WinForm.Controls.Grid
Imports sanMuSoft.CS.WinForm.Controls.BoxControls
Imports sanMuSoft.CS.Workflow
Imports sanMuSoft.CS.Report
Imports sanMuSoft.Data
Imports sanMuSoft.Data.TableBuilder

Namespace FormEvents
    Public Class Form2b15f5e9275f45df976bb78f46b70916
        Inherits FormEventsBase
        
        Public Sub 桌面Demo_Load(sender As Object,e As  System.EventArgs)
            Dim trvMenu As sanMuSoft.CS.WinForm.Controls.SmTreeView=CType(Me.SmForm.ControlDictionary()("trvMenu") ,sanMuSoft.CS.WinForm.Controls.SmTreeView)
            AutoMenu.CreateTreeView(trvMenu)
        End Sub
        
        Public Sub trvMenu_NodeMouseClick(sender As Object,e As  System.Windows.Forms.TreeNodeMouseClickEventArgs)
            If e.Node.Nodes.Count = 0 AndAlso e.Node.Name.StartsWith("qat") Then
                Dim strMenuID As String = e.Node.Name.Substring(3)              
                Try
                    AutoMenu.MenuClickForOpenForms(strMenuID)
                Catch ex As Exception
                    UnhandledExceptionManager.ShowAndSaveLog(ex)
                End Try
            End If
        End Sub
        
    End Class
End Namespace

C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
using System.Windows.Forms;
using Microsoft.CSharp;
using sanMuSoft.Utility;
using System.Threading;
using System.Net.Http;
using C1.C1Excel;
using C1.C1Zip;
using C1.Win.C1Command;
using C1.Win.C1FlexGrid;
using C1.Win.C1Input;
using C1.Win.C1Ribbon;
using C1.Win.C1Themes;
using sanMuSoft.CS.Framework;
using sanMuSoft.CS.Framework.Editor;
using sanMuSoft.CS.Framework.FormDesigner;
using sanMuSoft.CS.Framework.DropDownForms;
using sanMuSoft.CS.WinForm;
using sanMuSoft.CS.WinForm.Editor;
using sanMuSoft.CS.WinForm.Controls;
using sanMuSoft.CS.WinForm.Controls.Grid;
using sanMuSoft.CS.WinForm.Controls.BoxControls;
using sanMuSoft.CS.Workflow;
using sanMuSoft.CS.Report;
using sanMuSoft.Data;
using sanMuSoft.Data.TableBuilder;

namespace FormEvents
{
    public class Form2b15f5e9275f45df976bb78f46b70916 : FormEventsBase
    {
        public void 桌面Demo_Load(object sender, System.EventArgs e)
        {
            sanMuSoft.CS.WinForm.Controls.SmTreeView trvMenu = (sanMuSoft.CS.WinForm.Controls.SmTreeView)this.SmForm.ControlDictionary()("trvMenu");
            AutoMenu.CreateTreeView(trvMenu);
        }
        
        public void trvMenu_NodeMouseClick(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Nodes.Count == 0 && e.Node.Name.StartsWith("qat"))
            {
                string strMenuID = e.Node.Name.Substring(3);
                try
                {
                    AutoMenu.MenuClickForOpenForms(strMenuID);
                }
                catch (Exception ex)
                {
                    UnhandledExceptionManager.ShowAndSaveLog(ex);
                }
            }
        }
    }
}

第二步:在全局代码中创建相应的类,并继承类DesktopBase,重写OnLoad方法、DesktopType、PreviewImage、Description属性。

请根据下列示例中的代码改写自己的自定义桌面布局。这里在构造函数中引用了上一步创建的窗体,以及窗体中的C1DockingTab控件。

 Vb.Net
Imports System
Imports System.Text
Imports System.IO
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing.Text
Imports System.Diagnostics
Imports System.Collections
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Imports System.Collections.Specialized
Imports System.Windows.Forms
Imports System.Reflection
Imports Microsoft.CSharp
Imports Microsoft.VisualBasic
Imports sanMuSoft.Utility
Imports System.Linq
Imports System.Threading
Imports System.Threading.Tasks
Imports System.Net.Http
Imports C1.C1Excel
Imports C1.C1Zip
Imports C1.Win.C1Command
Imports C1.Win.C1FlexGrid
Imports C1.Win.C1Input
Imports C1.Win.C1Ribbon
Imports C1.Win.C1Themes
Imports sanMuSoft.CS.Framework
Imports sanMuSoft.CS.Framework.Editor
Imports sanMuSoft.CS.Framework.FormDesigner
Imports sanMuSoft.CS.Framework.DropDownForms
Imports sanMuSoft.CS.WinForm
Imports sanMuSoft.CS.WinForm.Editor
Imports sanMuSoft.CS.WinForm.Controls
Imports sanMuSoft.CS.WinForm.Controls.Grid
Imports sanMuSoft.CS.WinForm.Controls.BoxControls
Imports sanMuSoft.CS.Workflow
Imports sanMuSoft.CS.Report
Imports sanMuSoft.Data
Imports sanMuSoft.Data.TableBuilder

Namespace UserClass
    Public Class DeskTopDemo
        Inherits DesktopBase
        Private m_frm As BaseForm
        ''' <summary>
        ''' 构造函数
        ''' </summary>
        Public Sub New()
            '添加窗体到当前用户控件
            Dim frm As BaseForm=Proj.Forms.CreateNewFormByName("桌面Demo")
            '给窗口重命名一下,方便我们编辑窗体时不冲突
            frm.Name="Form" & Sys.Rand.NextString(8,False)
            '填充整个控件界面
            frm.Dock=DockStyle.Fill         
            '去除窗体的TopLevel属性才可以正常插入控件中
            frm.TopLevel=False
            '去除窗体的边框
            frm.FormBorderStyle = FormBorderStyle.None
            '将窗体添加到本控件中
            frm.Parent=Me
            '将窗体保存在变量中,方便其他地方调用
            m_frm=frm
            '所有的桌面必须有一个TabControl控件,必须将TabControl控件赋值给此基类的TabControlWithTables属性
            TabControlWithTables = frm.ControlDictionary()("tabMainTables")
            
            '修改桌面主题
            ChangeTheme()
        End Sub
        Protected Overrides Sub OnLoad(ByVal e As EventArgs)
            MyBase.OnLoad(e)
            '控件加载时,将相应的窗体也打开
            m_frm.Show()
        End Sub
        '此属性是为了方便在"系统界面选择"中展示桌面类型名称
        Public Overrides ReadOnly Property DesktopType As String
            Get
                Return "目录树导航Demo"
            End Get
        End Property
        '此属性是为了返回当前桌面的预览效果图
        Public Overrides ReadOnly Property PreviewImage As Image
            Get
                Return Sys.GetImage("DesktopLeftTreeView.png", Path.Combine(Proj.ApplicationPath, "Images"))
            End Get
        End Property
        '此属性是为了向使用者描述当前桌面的一些特征
        Public Overrides ReadOnly Property Description As String
            Get
                Return "通过左侧的目录树对系统实现导航功能。可以方便地搜索相应的模块功能。同时用户可以自定义自己常用菜单,让定位常用功能更加高效。比较适合系统功能特别复杂的场景。"
            End Get
        End Property
    End Class
End Namespace


C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
using System.Windows.Forms;
using Microsoft.CSharp;
using sanMuSoft.Utility;
using System.Threading;
using System.Net.Http;
using C1.C1Excel;
using C1.C1Zip;
using C1.Win.C1Command;
using C1.Win.C1FlexGrid;
using C1.Win.C1Input;
using C1.Win.C1Ribbon;
using C1.Win.C1Themes;
using sanMuSoft.CS.Framework;
using sanMuSoft.CS.Framework.Editor;
using sanMuSoft.CS.Framework.FormDesigner;
using sanMuSoft.CS.Framework.DropDownForms;
using sanMuSoft.CS.WinForm;
using sanMuSoft.CS.WinForm.Editor;
using sanMuSoft.CS.WinForm.Controls;
using sanMuSoft.CS.WinForm.Controls.Grid;
using sanMuSoft.CS.WinForm.Controls.BoxControls;
using sanMuSoft.CS.Workflow;
using sanMuSoft.CS.Report;
using sanMuSoft.Data;
using sanMuSoft.Data.TableBuilder;

namespace UserClass
{
    public class DeskTopDemo : DesktopBase
    {
        private BaseForm m_frm;
        /// <summary>
        /// 构造函数
        /// </summary>
        public DeskTopDemo()
        {
            // 添加窗体到当前用户控件
            BaseForm frm = Proj.Forms.CreateNewFormByName("桌面Demo");
            // 给窗口重命名一下,方便我们编辑窗体时不冲突
            frm.Name = "Form" + Sys.Rand.NextString(8, false);
            // 填充整个控件界面
            frm.Dock = DockStyle.Fill;
            // 去除窗体的TopLevel属性才可以正常插入控件中
            frm.TopLevel = false;
            // 去除窗体的边框
            frm.FormBorderStyle = FormBorderStyle.None;
            // 将窗体添加到本控件中
            frm.Parent = this;
            // 将窗体保存在变量中,方便其他地方调用
            m_frm = frm;
            // 所有的桌面必须有一个TabControl控件,必须将TabControl控件赋值给此基类的TabControlWithTables属性
            TabControlWithTables = frm.ControlDictionary()["tabMainTables"];

            // 修改桌面主题
            ChangeTheme();
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            // 控件加载时,将相应的窗体也打开
            m_frm.Show();
        }
        // 此属性是为了方便在"系统界面选择"中展示桌面类型名称
        public override string DesktopType
        {
            get
            {
                return "目录树导航Demo";
            }
        }
        // 此属性是为了返回当前桌面的预览效果图
        public override Image PreviewImage
        {
            get
            {
                return Sys.GetImage("DesktopLeftTreeView.png", Path.Combine(Proj.ApplicationPath, "Images"));
            }
        }
        // 此属性是为了向使用者描述当前桌面的一些特征
        public override string Description
        {
            get
            {
                return "通过左侧的目录树对系统实现导航功能。可以方便地搜索相应的模块功能。同时用户可以自定义自己常用菜单,让定位常用功能更加高效。比较适合系统功能特别复杂的场景。";
            }
        }
    }
}

第三步:重启软件。然后可以到菜单中的“系统界面选择”菜单打开相应的窗体,这时候我们就可以看到自己写的界面布局已经在选择项中了。选择,然后点确定按钮,就可以切换到自定义的界面布局中了。