[C#] Visual Studio风格的窗体 →→→→→进入此内容的聊天室

来自 , 2019-09-15, 写在 C#, 查看 125 次.
URL http://www.code666.cn/view/a8aa681a
  1. //MainForm.cs
  2.  
  3. using System;
  4. using System.Drawing;
  5. using System.Collections;
  6. using System.ComponentModel;
  7. using System.Reflection;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using DockSample.Customization;
  11. using Lextm.SharpSnmpLib;
  12. using WeifenLuo.WinFormsUI.Docking;
  13.  
  14. namespace DockSample
  15. {
  16.     public partial class MainForm : Form
  17.     {
  18.         private bool m_bSaveLayout = true;
  19.         private DeserializeDockContent m_deserializeDockContent;
  20.         private DummySolutionExplorer m_solutionExplorer;
  21.         private DummyPropertyWindow m_propertyWindow;
  22.         private DummyToolbox m_toolbox;
  23.         private DummyOutputWindow m_outputWindow;
  24.         private DummyTaskList m_taskList;
  25.         private bool _showSplash;
  26.         private SplashScreen _splashScreen;
  27.         public MainForm()
  28.         {
  29.             InitializeComponent();
  30.  
  31.             SetSplashScreen();
  32.             CreateStandardControls();
  33.  
  34.             showRightToLeft.Checked = (RightToLeft == RightToLeft.Yes);
  35.             RightToLeftLayout = showRightToLeft.Checked;
  36.             m_solutionExplorer.RightToLeftLayout = RightToLeftLayout;
  37.             m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
  38.            
  39.             vS2012ToolStripExtender1.DefaultRenderer = _toolStripProfessionalRenderer;
  40.             vS2012ToolStripExtender1.VS2012Renderer = _vs2012ToolStripRenderer;
  41.             vS2012ToolStripExtender1.VS2013Renderer = _vs2013ToolStripRenderer;
  42.  
  43.             this.topBar.BackColor = this.bottomBar.BackColor = Color.FromArgb(0xFF, 41, 57, 85);
  44.  
  45.             SetSchema(this.menuItemSchemaVS2013Blue, null);
  46.         }
  47.  
  48.         #region Methods
  49.  
  50.         private IDockContent FindDocument(string text)
  51.         {
  52.             if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  53.             {
  54.                 foreach (Form form in MdiChildren)
  55.                     if (form.Text == text)
  56.                         return form as IDockContent;
  57.  
  58.                 return null;
  59.             }
  60.             else
  61.             {
  62.                 foreach (IDockContent content in dockPanel.Documents)
  63.                     if (content.DockHandler.TabText == text)
  64.                         return content;
  65.  
  66.                 return null;
  67.             }
  68.         }
  69.  
  70.         private DummyDoc CreateNewDocument()
  71.         {
  72.             DummyDoc dummyDoc = new DummyDoc();
  73.  
  74.             int count = 1;
  75.             //string text = "C:\\MADFDKAJ\\ADAKFJASD\\ADFKDSAKFJASD\\ASDFKASDFJASDF\\ASDFIJADSFJ\\ASDFKDFDA" + count.ToString();
  76.             string text = "Document" + count.ToString();
  77.             while (FindDocument(text) != null)
  78.             {
  79.                 count++;
  80.                 //text = "C:\\MADFDKAJ\\ADAKFJASD\\ADFKDSAKFJASD\\ASDFKASDFJASDF\\ASDFIJADSFJ\\ASDFKDFDA" + count.ToString();
  81.                 text = "Document" + count.ToString();
  82.             }
  83.             dummyDoc.Text = text;
  84.             return dummyDoc;
  85.         }
  86.  
  87.         private DummyDoc CreateNewDocument(string text)
  88.         {
  89.             DummyDoc dummyDoc = new DummyDoc();
  90.             dummyDoc.Text = text;
  91.             return dummyDoc;
  92.         }
  93.  
  94.         private void CloseAllDocuments()
  95.         {
  96.             if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  97.             {
  98.                 foreach (Form form in MdiChildren)
  99.                     form.Close();
  100.             }
  101.             else
  102.             {
  103.                 foreach (IDockContent document in dockPanel.DocumentsToArray())
  104.                 {
  105.                     document.DockHandler.Close();
  106.                 }
  107.             }
  108.         }
  109.  
  110.         private IDockContent GetContentFromPersistString(string persistString)
  111.         {
  112.             if (persistString == typeof(DummySolutionExplorer).ToString())
  113.                 return m_solutionExplorer;
  114.             else if (persistString == typeof(DummyPropertyWindow).ToString())
  115.                 return m_propertyWindow;
  116.             else if (persistString == typeof(DummyToolbox).ToString())
  117.                 return m_toolbox;
  118.             else if (persistString == typeof(DummyOutputWindow).ToString())
  119.                 return m_outputWindow;
  120.             else if (persistString == typeof(DummyTaskList).ToString())
  121.                 return m_taskList;
  122.             else
  123.             {
  124.                 // DummyDoc overrides GetPersistString to add extra information into persistString.
  125.                 // Any DockContent may override this value to add any needed information for deserialization.
  126.  
  127.                 string[] parsedStrings = persistString.Split(new char[] { ',' });
  128.                 if (parsedStrings.Length != 3)
  129.                     return null;
  130.  
  131.                 if (parsedStrings[0] != typeof(DummyDoc).ToString())
  132.                     return null;
  133.  
  134.                 DummyDoc dummyDoc = new DummyDoc();
  135.                 if (parsedStrings[1] != string.Empty)
  136.                     dummyDoc.FileName = parsedStrings[1];
  137.                 if (parsedStrings[2] != string.Empty)
  138.                     dummyDoc.Text = parsedStrings[2];
  139.  
  140.                 return dummyDoc;
  141.             }
  142.         }
  143.  
  144.         private void CloseAllContents()
  145.         {
  146.             // we don't want to create another instance of tool window, set DockPanel to null
  147.             m_solutionExplorer.DockPanel = null;
  148.             m_propertyWindow.DockPanel = null;
  149.             m_toolbox.DockPanel = null;
  150.             m_outputWindow.DockPanel = null;
  151.             m_taskList.DockPanel = null;
  152.  
  153.             // Close all other document windows
  154.             CloseAllDocuments();
  155.         }
  156.  
  157.         private readonly ToolStripRenderer _toolStripProfessionalRenderer = new ToolStripProfessionalRenderer();
  158.         private readonly ToolStripRenderer _vs2012ToolStripRenderer = new VS2012ToolStripRenderer();
  159.         private readonly ToolStripRenderer _vs2013ToolStripRenderer = new Vs2013ToolStripRenderer();
  160.        
  161.         private void SetSchema(object sender, System.EventArgs e)
  162.         {
  163.             // Persist settings when rebuilding UI
  164.             string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.temp.config");
  165.  
  166.             dockPanel.SaveAsXml(configFile);
  167.             CloseAllContents();
  168.  
  169.             if (sender == this.menuItemSchemaVS2005)
  170.             {
  171.                 this.dockPanel.Theme = this.vS2005Theme1;
  172.                 this.EnableVSRenderer(VSToolStripExtender.VsVersion.Vs2005);
  173.             }
  174.             else if (sender == this.menuItemSchemaVS2003)
  175.             {
  176.                 this.dockPanel.Theme = this.vS2003Theme1;
  177.                 this.EnableVSRenderer(VSToolStripExtender.VsVersion.Vs2003);
  178.             }
  179.             else if (sender == this.menuItemSchemaVS2012Light)
  180.             {
  181.                 this.dockPanel.Theme = this.vS2012LightTheme1;
  182.                 this.EnableVSRenderer(VSToolStripExtender.VsVersion.Vs2012);
  183.             }
  184.             else if (sender == this.menuItemSchemaVS2013Blue)
  185.             {
  186.                 this.dockPanel.Theme = this.vS2013BlueTheme1;
  187.                 this.EnableVSRenderer(VSToolStripExtender.VsVersion.Vs2013);
  188.             }
  189.  
  190.             menuItemSchemaVS2005.Checked = (sender == menuItemSchemaVS2005);
  191.             menuItemSchemaVS2003.Checked = (sender == menuItemSchemaVS2003);
  192.             menuItemSchemaVS2012Light.Checked = (sender == menuItemSchemaVS2012Light);
  193.             this.menuItemSchemaVS2013Blue.Checked = (sender == this.menuItemSchemaVS2013Blue);
  194.             this.topBar.Visible = this.bottomBar.Visible = (sender == this.menuItemSchemaVS2013Blue);
  195.  
  196.             if (File.Exists(configFile))
  197.                 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
  198.         }
  199.  
  200.         private void EnableVSRenderer(VSToolStripExtender.VsVersion version)
  201.         {
  202.             vS2012ToolStripExtender1.SetStyle(this.mainMenu, version);
  203.             vS2012ToolStripExtender1.SetStyle(this.toolBar, version);
  204.             vS2012ToolStripExtender1.SetStyle(this.statusBar, version);
  205.         }
  206.  
  207.         private void SetDocumentStyle(object sender, System.EventArgs e)
  208.         {
  209.             DocumentStyle oldStyle = dockPanel.DocumentStyle;
  210.             DocumentStyle newStyle;
  211.             if (sender == menuItemDockingMdi)
  212.                 newStyle = DocumentStyle.DockingMdi;
  213.             else if (sender == menuItemDockingWindow)
  214.                 newStyle = DocumentStyle.DockingWindow;
  215.             else if (sender == menuItemDockingSdi)
  216.                 newStyle = DocumentStyle.DockingSdi;
  217.             else
  218.                 newStyle = DocumentStyle.SystemMdi;
  219.  
  220.             if (oldStyle == newStyle)
  221.                 return;
  222.  
  223.             if (oldStyle == DocumentStyle.SystemMdi || newStyle == DocumentStyle.SystemMdi)
  224.                 CloseAllDocuments();
  225.  
  226.             dockPanel.DocumentStyle = newStyle;
  227.             menuItemDockingMdi.Checked = (newStyle == DocumentStyle.DockingMdi);
  228.             menuItemDockingWindow.Checked = (newStyle == DocumentStyle.DockingWindow);
  229.             menuItemDockingSdi.Checked = (newStyle == DocumentStyle.DockingSdi);
  230.             menuItemSystemMdi.Checked = (newStyle == DocumentStyle.SystemMdi);
  231.             menuItemLayoutByCode.Enabled = (newStyle != DocumentStyle.SystemMdi);
  232.             menuItemLayoutByXml.Enabled = (newStyle != DocumentStyle.SystemMdi);
  233.             toolBarButtonLayoutByCode.Enabled = (newStyle != DocumentStyle.SystemMdi);
  234.             toolBarButtonLayoutByXml.Enabled = (newStyle != DocumentStyle.SystemMdi);
  235.         }
  236.  
  237.         private AutoHideStripSkin _autoHideStripSkin;
  238.         private DockPaneStripSkin _dockPaneStripSkin;
  239.  
  240.         private void SetDockPanelSkinOptions(bool isChecked)
  241.         {
  242.             if (isChecked)
  243.             {
  244.                 // All of these options may be set in the designer.
  245.                 // This is not a complete list of possible options available in the skin.
  246.  
  247.                 AutoHideStripSkin autoHideSkin = new AutoHideStripSkin();
  248.                 autoHideSkin.DockStripGradient.StartColor = Color.AliceBlue;
  249.                 autoHideSkin.DockStripGradient.EndColor = Color.Blue;
  250.                 autoHideSkin.DockStripGradient.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal;
  251.                 autoHideSkin.TabGradient.StartColor = SystemColors.Control;
  252.                 autoHideSkin.TabGradient.EndColor = SystemColors.ControlDark;
  253.                 autoHideSkin.TabGradient.TextColor = SystemColors.ControlText;
  254.                 autoHideSkin.TextFont = new Font("Showcard Gothic", 10);
  255.  
  256.                 _autoHideStripSkin = dockPanel.Skin.AutoHideStripSkin;
  257.                 dockPanel.Skin.AutoHideStripSkin = autoHideSkin;
  258.  
  259.                 DockPaneStripSkin dockPaneSkin = new DockPaneStripSkin();
  260.                 dockPaneSkin.DocumentGradient.DockStripGradient.StartColor = Color.Red;
  261.                 dockPaneSkin.DocumentGradient.DockStripGradient.EndColor = Color.Pink;
  262.  
  263.                 dockPaneSkin.DocumentGradient.ActiveTabGradient.StartColor = Color.Green;
  264.                 dockPaneSkin.DocumentGradient.ActiveTabGradient.EndColor = Color.Green;
  265.                 dockPaneSkin.DocumentGradient.ActiveTabGradient.TextColor = Color.White;
  266.  
  267.                 dockPaneSkin.DocumentGradient.InactiveTabGradient.StartColor = Color.Gray;
  268.                 dockPaneSkin.DocumentGradient.InactiveTabGradient.EndColor = Color.Gray;
  269.                 dockPaneSkin.DocumentGradient.InactiveTabGradient.TextColor = Color.Black;
  270.  
  271.                 dockPaneSkin.TextFont = new Font("SketchFlow Print", 10);
  272.  
  273.                 _dockPaneStripSkin = dockPanel.Skin.DockPaneStripSkin;
  274.                 dockPanel.Skin.DockPaneStripSkin = dockPaneSkin;
  275.             }
  276.             else
  277.             {
  278.                 if (_autoHideStripSkin != null)
  279.                 {
  280.                     dockPanel.Skin.AutoHideStripSkin = _autoHideStripSkin;
  281.                 }
  282.  
  283.                 if (_dockPaneStripSkin != null)
  284.                 {
  285.                     dockPanel.Skin.DockPaneStripSkin = _dockPaneStripSkin;
  286.                 }
  287.             }
  288.  
  289.             menuItemLayoutByXml_Click(menuItemLayoutByXml, EventArgs.Empty);
  290.         }
  291.  
  292.         #endregion
  293.  
  294.         #region Event Handlers
  295.  
  296.         private void menuItemExit_Click(object sender, System.EventArgs e)
  297.         {
  298.             Close();
  299.         }
  300.  
  301.         private void menuItemSolutionExplorer_Click(object sender, System.EventArgs e)
  302.         {
  303.             m_solutionExplorer.Show(dockPanel);
  304.         }
  305.  
  306.         private void menuItemPropertyWindow_Click(object sender, System.EventArgs e)
  307.         {
  308.             m_propertyWindow.Show(dockPanel);
  309.         }
  310.  
  311.         private void menuItemToolbox_Click(object sender, System.EventArgs e)
  312.         {
  313.             m_toolbox.Show(dockPanel);
  314.         }
  315.  
  316.         private void menuItemOutputWindow_Click(object sender, System.EventArgs e)
  317.         {
  318.             m_outputWindow.Show(dockPanel);
  319.         }
  320.  
  321.         private void menuItemTaskList_Click(object sender, System.EventArgs e)
  322.         {
  323.             m_taskList.Show(dockPanel);
  324.         }
  325.  
  326.         private void menuItemAbout_Click(object sender, System.EventArgs e)
  327.         {
  328.             AboutDialog aboutDialog = new AboutDialog();
  329.             aboutDialog.ShowDialog(this);
  330.         }
  331.  
  332.         private void menuItemNew_Click(object sender, System.EventArgs e)
  333.         {
  334.             DummyDoc dummyDoc = CreateNewDocument();
  335.             if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  336.             {
  337.                 dummyDoc.MdiParent = this;
  338.                 dummyDoc.Show();
  339.             }
  340.             else
  341.                 dummyDoc.Show(dockPanel);
  342.         }
  343.  
  344.         private void menuItemOpen_Click(object sender, System.EventArgs e)
  345.         {
  346.             OpenFileDialog openFile = new OpenFileDialog();
  347.  
  348.             openFile.InitialDirectory = Application.ExecutablePath;
  349.             openFile.Filter = "rtf files (*.rtf)|*.rtf|txt files (*.txt)|*.txt|All files (*.*)|*.*";
  350.             openFile.FilterIndex = 1;
  351.             openFile.RestoreDirectory = true;
  352.  
  353.             if (openFile.ShowDialog() == DialogResult.OK)
  354.             {
  355.                 string fullName = openFile.FileName;
  356.                 string fileName = Path.GetFileName(fullName);
  357.  
  358.                 if (FindDocument(fileName) != null)
  359.                 {
  360.                     MessageBox.Show("The document: " + fileName + " has already opened!");
  361.                     return;
  362.                 }
  363.  
  364.                 DummyDoc dummyDoc = new DummyDoc();
  365.                 dummyDoc.Text = fileName;
  366.                 if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  367.                 {
  368.                     dummyDoc.MdiParent = this;
  369.                     dummyDoc.Show();
  370.                 }
  371.                 else
  372.                     dummyDoc.Show(dockPanel);
  373.                 try
  374.                 {
  375.                     dummyDoc.FileName = fullName;
  376.                 }
  377.                 catch (Exception exception)
  378.                 {
  379.                     dummyDoc.Close();
  380.                     MessageBox.Show(exception.Message);
  381.                 }
  382.  
  383.             }
  384.         }
  385.  
  386.         private void menuItemFile_Popup(object sender, System.EventArgs e)
  387.         {
  388.             if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  389.             {
  390.                 menuItemClose.Enabled =
  391.                     menuItemCloseAll.Enabled =
  392.                     menuItemCloseAllButThisOne.Enabled = (ActiveMdiChild != null);
  393.             }
  394.             else
  395.             {
  396.                 menuItemClose.Enabled = (dockPanel.ActiveDocument != null);
  397.                 menuItemCloseAll.Enabled =
  398.                     menuItemCloseAllButThisOne.Enabled = (dockPanel.DocumentsCount > 0);
  399.             }
  400.         }
  401.  
  402.         private void menuItemClose_Click(object sender, System.EventArgs e)
  403.         {
  404.             if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  405.                 ActiveMdiChild.Close();
  406.             else if (dockPanel.ActiveDocument != null)
  407.                 dockPanel.ActiveDocument.DockHandler.Close();
  408.         }
  409.  
  410.         private void menuItemCloseAll_Click(object sender, System.EventArgs e)
  411.         {
  412.             CloseAllDocuments();
  413.         }
  414.  
  415.         private void MainForm_Load(object sender, System.EventArgs e)
  416.         {
  417.             string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
  418.  
  419.             if (File.Exists(configFile))
  420.                 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
  421.         }
  422.  
  423.         private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  424.         {
  425.             string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
  426.             if (m_bSaveLayout)
  427.                 dockPanel.SaveAsXml(configFile);
  428.             else if (File.Exists(configFile))
  429.                 File.Delete(configFile);
  430.         }
  431.  
  432.         private void menuItemToolBar_Click(object sender, System.EventArgs e)
  433.         {
  434.             toolBar.Visible = menuItemToolBar.Checked = !menuItemToolBar.Checked;
  435.         }
  436.  
  437.         private void menuItemStatusBar_Click(object sender, System.EventArgs e)
  438.         {
  439.             statusBar.Visible = menuItemStatusBar.Checked = !menuItemStatusBar.Checked;
  440.         }
  441.  
  442.         private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolStripItemClickedEventArgs e)
  443.         {
  444.             if (e.ClickedItem == toolBarButtonNew)
  445.                 menuItemNew_Click(null, null);
  446.             else if (e.ClickedItem == toolBarButtonOpen)
  447.                 menuItemOpen_Click(null, null);
  448.             else if (e.ClickedItem == toolBarButtonSolutionExplorer)
  449.                 menuItemSolutionExplorer_Click(null, null);
  450.             else if (e.ClickedItem == toolBarButtonPropertyWindow)
  451.                 menuItemPropertyWindow_Click(null, null);
  452.             else if (e.ClickedItem == toolBarButtonToolbox)
  453.                 menuItemToolbox_Click(null, null);
  454.             else if (e.ClickedItem == toolBarButtonOutputWindow)
  455.                 menuItemOutputWindow_Click(null, null);
  456.             else if (e.ClickedItem == toolBarButtonTaskList)
  457.                 menuItemTaskList_Click(null, null);
  458.             else if (e.ClickedItem == toolBarButtonLayoutByCode)
  459.                 menuItemLayoutByCode_Click(null, null);
  460.             else if (e.ClickedItem == toolBarButtonLayoutByXml)
  461.                 menuItemLayoutByXml_Click(null, null);
  462.             else if (e.ClickedItem == toolBarButtonDockPanelSkinDemo)
  463.                 SetDockPanelSkinOptions(!toolBarButtonDockPanelSkinDemo.Checked);
  464.         }
  465.  
  466.         private void menuItemNewWindow_Click(object sender, System.EventArgs e)
  467.         {
  468.             MainForm newWindow = new MainForm();
  469.             newWindow.Text = newWindow.Text + " - New";
  470.             newWindow.Show();
  471.         }
  472.  
  473.         private void menuItemTools_Popup(object sender, System.EventArgs e)
  474.         {
  475.             menuItemLockLayout.Checked = !this.dockPanel.AllowEndUserDocking;
  476.         }
  477.  
  478.         private void menuItemLockLayout_Click(object sender, System.EventArgs e)
  479.         {
  480.             dockPanel.AllowEndUserDocking = !dockPanel.AllowEndUserDocking;
  481.         }
  482.  
  483.         private void menuItemLayoutByCode_Click(object sender, System.EventArgs e)
  484.         {
  485.             dockPanel.SuspendLayout(true);
  486.  
  487.             CloseAllContents();
  488.  
  489.             CreateStandardControls();
  490.  
  491.             m_solutionExplorer.Show(dockPanel, DockState.DockRight);
  492.             m_propertyWindow.Show(m_solutionExplorer.Pane, m_solutionExplorer);
  493.             m_toolbox.Show(dockPanel, new Rectangle(98, 133, 200, 383));
  494.             m_outputWindow.Show(m_solutionExplorer.Pane, DockAlignment.Bottom, 0.35);
  495.             m_taskList.Show(m_toolbox.Pane, DockAlignment.Left, 0.4);
  496.  
  497.             DummyDoc doc1 = CreateNewDocument("Document1");
  498.             DummyDoc doc2 = CreateNewDocument("Document2");
  499.             DummyDoc doc3 = CreateNewDocument("Document3");
  500.             DummyDoc doc4 = CreateNewDocument("Document4");
  501.             doc1.Show(dockPanel, DockState.Document);
  502.             doc2.Show(doc1.Pane, null);
  503.             doc3.Show(doc1.Pane, DockAlignment.Bottom, 0.5);
  504.             doc4.Show(doc3.Pane, DockAlignment.Right, 0.5);
  505.  
  506.             dockPanel.ResumeLayout(true, true);
  507.         }
  508.  
  509.         private void SetSplashScreen()
  510.         {
  511.            
  512.             _showSplash = true;
  513.             _splashScreen = new SplashScreen();
  514.  
  515.             ResizeSplash();
  516.             _splashScreen.Visible = true;
  517.             _splashScreen.TopMost = true;
  518.  
  519.             Timer _timer = new Timer();
  520.             _timer.Tick += (sender, e) =>
  521.             {
  522.                 _splashScreen.Visible = false;
  523.                 _timer.Enabled = false;
  524.                 _showSplash = false;
  525.             };
  526.             _timer.Interval = 4000;
  527.             _timer.Enabled = true;
  528.         }
  529.  
  530.         private void ResizeSplash()
  531.         {
  532.             if (_showSplash) {
  533.                
  534.             var centerXMain = (this.Location.X + this.Width) / 2.0;
  535.             var LocationXSplash = Math.Max(0, centerXMain - (_splashScreen.Width / 2.0));
  536.  
  537.             var centerYMain = (this.Location.Y + this.Height) / 2.0;
  538.             var LocationYSplash = Math.Max(0, centerYMain - (_splashScreen.Height / 2.0));
  539.  
  540.             _splashScreen.Location = new Point((int)Math.Round(LocationXSplash), (int)Math.Round(LocationYSplash));
  541.             }
  542.         }
  543.  
  544.         private void CreateStandardControls()
  545.         {
  546.             m_solutionExplorer = new DummySolutionExplorer();
  547.             m_propertyWindow = new DummyPropertyWindow();
  548.             m_toolbox = new DummyToolbox();
  549.             m_outputWindow = new DummyOutputWindow();
  550.             m_taskList = new DummyTaskList();
  551.         }
  552.  
  553.         private void menuItemLayoutByXml_Click(object sender, System.EventArgs e)
  554.         {
  555.             dockPanel.SuspendLayout(true);
  556.  
  557.             // In order to load layout from XML, we need to close all the DockContents
  558.             CloseAllContents();
  559.  
  560.             CreateStandardControls();
  561.  
  562.             Assembly assembly = Assembly.GetAssembly(typeof(MainForm));
  563.             Stream xmlStream = assembly.GetManifestResourceStream("DockSample.Resources.DockPanel.xml");
  564.             dockPanel.LoadFromXml(xmlStream, m_deserializeDockContent);
  565.             xmlStream.Close();
  566.  
  567.             dockPanel.ResumeLayout(true, true);
  568.         }
  569.  
  570.         private void menuItemCloseAllButThisOne_Click(object sender, System.EventArgs e)
  571.         {
  572.             if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
  573.             {
  574.                 Form activeMdi = ActiveMdiChild;
  575.                 foreach (Form form in MdiChildren)
  576.                 {
  577.                     if (form != activeMdi)
  578.                         form.Close();
  579.                 }
  580.             }
  581.             else
  582.             {
  583.                 foreach (IDockContent document in dockPanel.DocumentsToArray())
  584.                 {
  585.                     if (!document.DockHandler.IsActivated)
  586.                         document.DockHandler.Close();
  587.                 }
  588.             }
  589.         }
  590.  
  591.         private void menuItemShowDocumentIcon_Click(object sender, System.EventArgs e)
  592.         {
  593.             dockPanel.ShowDocumentIcon = menuItemShowDocumentIcon.Checked = !menuItemShowDocumentIcon.Checked;
  594.         }
  595.  
  596.         private void showRightToLeft_Click(object sender, EventArgs e)
  597.         {
  598.             CloseAllContents();
  599.             if (showRightToLeft.Checked)
  600.             {
  601.                 this.RightToLeft = RightToLeft.No;
  602.                 this.RightToLeftLayout = false;
  603.             }
  604.             else
  605.             {
  606.                 this.RightToLeft = RightToLeft.Yes;
  607.                 this.RightToLeftLayout = true;
  608.             }
  609.             m_solutionExplorer.RightToLeftLayout = this.RightToLeftLayout;
  610.             showRightToLeft.Checked = !showRightToLeft.Checked;
  611.         }
  612.  
  613.         private void exitWithoutSavingLayout_Click(object sender, EventArgs e)
  614.         {
  615.             m_bSaveLayout = false;
  616.             Close();
  617.             m_bSaveLayout = true;
  618.         }
  619.  
  620.         #endregion
  621.  
  622.         private void MainForm_SizeChanged(object sender, EventArgs e)
  623.         {
  624.             ResizeSplash();
  625.         }
  626.     }
  627. }

回复 "Visual Studio风格的窗体"

这儿你可以回复上面这条便签

captcha