📄 dockablecontrol.cs
字号:
// DockableControl.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Xml;
using SharpDevelop.Tool.Data;
namespace SharpDevelop.Gui.Docking {
public enum DockedIn {
LeftContainer,
RightContainer,
TopContainer,
BottomContainer
}
public class DockState : XmlConvertable
{
public bool Visible = true;
public bool Float = true;
public Rectangle Bounds = new Rectangle(0, 0, -1, -1);
public DockedIn DockedIn = DockedIn.LeftContainer;
public DockState()
{
}
public DockState(XmlElement element)
{
string[] boundstr = element.InnerText.Split(new char [] {'|'});
Bounds = new Rectangle (Int32.Parse(boundstr[0]),
Int32.Parse(boundstr[1]),
Int32.Parse(boundstr[2]),
Int32.Parse(boundstr[3]));
Visible = Boolean.Parse(element.Attributes["Visible"].InnerText);
Float = Boolean.Parse(element.Attributes["Floating"].InnerText);
DockedIn = (DockedIn)Enum.Parse(typeof(DockedIn), element.Attributes["DockedIn"].InnerText);
}
public object FromXmlElement(XmlElement element)
{
return new DockState(element);
}
public XmlElement ToXmlElement(XmlDocument doc)
{
XmlElement element = doc.CreateElement("DockState");
element.InnerText = Bounds.X + "|" +
Bounds.Y + "|" +
Bounds.Width + "|" +
Bounds.Height;
XmlAttribute attr1 = doc.CreateAttribute("Floating");
attr1.InnerText = Float.ToString();
element.Attributes.Append(attr1);
XmlAttribute attr2 = doc.CreateAttribute("Visible");
attr2.InnerText = Visible.ToString();
element.Attributes.Append(attr2);
XmlAttribute attr3 = doc.CreateAttribute("DockedIn");
attr3.InnerText = DockedIn.ToString();
element.Attributes.Append(attr3);
return element;
}
}
public class DockableControl : Panel
{
public string WindowName = "";
public string TabName = "";
public Form FormContainer = null;
public TabControl TabControl = null;
public TabPage TabPage = null;
int tabnumber = 0;
DockState dockstate = new DockState();
public event EventHandler DockedVisibleChanged;
public void ShowDockedControl()
{
dockstate.Visible = true;
Show();
if (FormContainer != null)
FormContainer.Show();
if (TabControl != null) {
TabControl.TabPages.Add(TabPage);
}
if (DockedVisibleChanged != null)
DockedVisibleChanged(this, null);
}
public void HideDockedControl()
{
dockstate.Visible = false;
Hide();
if (FormContainer != null)
FormContainer.Hide();
if (TabPage != null) {
tabnumber = TabControl.TabPages.IndexOf(TabPage);
TabControl.TabPages.Remove(TabPage);
}
if (DockedVisibleChanged != null)
DockedVisibleChanged(this, null);
}
public DockState DockState {
get {
if (FormContainer != null)
dockstate.Bounds = FormContainer.Bounds;
return dockstate;
}
set {
dockstate = value;
if (dockstate == null)
dockstate =new DockState();
}
}
public ContextMenu formatmenu = null;
MouseEventArgs meventargs;
protected void OnMouseDown(object sender, MouseEventArgs e)
{
meventargs = e;
base.OnMouseDown(e);
}
protected void OnClick(object sender, EventArgs e)
{
base.OnClick(e);
if (meventargs.Button == MouseButtons.Middle && formatmenu != null) {
formatmenu.Show(this, new Point(meventargs.X, meventargs.Y));
}
}
public DockableControl()
{
Dock = DockStyle.Fill;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -