📄 xtabcontorldesigner.cs
字号:
namespace Imps.Client.Pc.XControls
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
public class XTabContorlDesigner : ParentControlDesigner
{
private bool addingOnInitialize;
private bool forwardOnDrag;
private DesignerVerb removeVerb;
private bool tabControlSelected;
private DesignerVerbCollection verbs;
public override bool CanParent(Control control)
{
if (this.Control is XTabPage)
{
return !this.Control.Contains(control);
}
return false;
}
private void CheckVerbStatus()
{
if (this.removeVerb != null)
{
this.removeVerb.Enabled = this.Control.Controls.get_Count() > 0;
}
}
protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
{
XTabControl control = (XTabControl) this.Control;
if (control.SelectedTab == null)
{
throw new ArgumentException("");
}
IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost));
if (service != null)
{
XTabPageDesigner toInvoke = (XTabPageDesigner) service.GetDesigner(control.SelectedTab);
ParentControlDesigner.InvokeCreateTool(toInvoke, tool);
}
return null;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService));
if (service != null)
{
service.SelectionChanged -= new EventHandler(this.OnSelectionChanged);
}
IComponentChangeService service2 = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
if (service2 != null)
{
service2.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
}
XTabControl control = this.Control as XTabControl;
if (control != null)
{
control.SelectedIndexChanged -= new EventHandler(this.OnTabSelectedIndexChanged);
control.GotFocus -= new EventHandler(this.OnGotFocus);
}
}
base.Dispose(disposing);
}
protected override bool GetHitTest(Point point)
{
XTabControl control = this.Control as XTabControl;
if ((control != null) && this.tabControlSelected)
{
Point pt = this.Control.PointToClient(point);
return !control.DisplayRectangle.Contains(pt);
}
return false;
}
private XTabPageDesigner GetSelectedTabPageDesigner()
{
XTabPageDesigner designer = null;
XTabPage component = ((XTabControl) base.Component).SelectedTab;
if (component != null)
{
IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost));
if (service != null)
{
designer = service.GetDesigner(component) as XTabPageDesigner;
}
}
return designer;
}
private static XTabPage GetTabPageOfComponent(object comp)
{
if (!(comp is Control))
{
return null;
}
Control parent = (Control) comp;
while ((parent != null) && !(parent is XTabPage))
{
parent = parent.Parent;
}
return (XTabPage) parent;
}
public override void Initialize(IComponent component)
{
base.Initialize(component);
base.AutoResizeHandles = true;
XTabControl control = component as XTabControl;
ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService));
if (service != null)
{
service.SelectionChanged += new EventHandler(this.OnSelectionChanged);
}
IComponentChangeService service2 = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
if (service2 != null)
{
service2.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
}
if (control != null)
{
control.SelectedIndexChanged += new EventHandler(this.OnTabSelectedIndexChanged);
control.GotFocus += new EventHandler(this.OnGotFocus);
}
}
public override void InitializeNewComponent(IDictionary defaultValues)
{
base.InitializeNewComponent(defaultValues);
try
{
this.addingOnInitialize = true;
this.OnAdd(this, EventArgs.Empty);
this.OnAdd(this, EventArgs.Empty);
}
finally
{
this.addingOnInitialize = false;
}
MemberDescriptor member = TypeDescriptor.GetProperties(base.Component)["Controls"];
base.RaiseComponentChanging(member);
base.RaiseComponentChanged(member, null, null);
XTabControl component = (XTabControl) base.Component;
if (component != null)
{
component.SelectedIndex = 0;
}
}
private void OnAdd(object sender, EventArgs e)
{
XTabControl component = (XTabControl) base.Component;
IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost));
if (service != null)
{
DesignerTransaction transaction = null;
try
{
MemberDescriptor member = TypeDescriptor.GetProperties(component)["Controls"];
XTabPage page = (XTabPage) service.CreateComponent(typeof(XTabPage));
if (!this.addingOnInitialize)
{
base.RaiseComponentChanging(member);
}
page.set_Padding(new Padding(3));
string text = null;
PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(page)["Name"];
if ((descriptor2 != null) && (descriptor2.PropertyType == typeof(string)))
{
text = (string) descriptor2.GetValue(page);
}
if (text != null)
{
PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(page)["Text"];
if (descriptor3 != null)
{
descriptor3.SetValue(page, text);
}
}
PropertyDescriptor descriptor4 = TypeDescriptor.GetProperties(page)["UseVisualStyleBackColor"];
if (((descriptor4 != null) && (descriptor4.PropertyType == typeof(bool))) && (!descriptor4.IsReadOnly && descriptor4.IsBrowsable))
{
descriptor4.SetValue(page, true);
}
component.Controls.Add(page);
component.SelectedIndex = component.TabCount - 1;
if (!this.addingOnInitialize)
{
base.RaiseComponentChanged(member, null, null);
}
}
finally
{
if (transaction != null)
{
transaction.Commit();
}
}
}
}
private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
{
this.CheckVerbStatus();
}
protected override void OnDragDrop(DragEventArgs de)
{
if (this.forwardOnDrag)
{
XTabPageDesigner selectedTabPageDesigner = this.GetSelectedTabPageDesigner();
if (selectedTabPageDesigner != null)
{
selectedTabPageDesigner.OnDragDropInternal(de);
}
}
else
{
base.OnDragDrop(de);
}
this.forwardOnDrag = false;
}
protected override void OnDragEnter(DragEventArgs de)
{
this.forwardOnDrag = true;
if (this.forwardOnDrag)
{
XTabPageDesigner selectedTabPageDesigner = this.GetSelectedTabPageDesigner();
if (selectedTabPageDesigner != null)
{
selectedTabPageDesigner.OnDragEnterInternal(de);
}
}
else
{
base.OnDragEnter(de);
}
}
protected override void OnDragLeave(EventArgs e)
{
if (this.forwardOnDrag)
{
XTabPageDesigner selectedTabPageDesigner = this.GetSelectedTabPageDesigner();
if (selectedTabPageDesigner != null)
{
selectedTabPageDesigner.OnDragLeaveInternal(e);
}
}
else
{
base.OnDragLeave(e);
}
this.forwardOnDrag = false;
}
protected override void OnDragOver(DragEventArgs de)
{
if (this.forwardOnDrag)
{
XTabControl control = (XTabControl) this.Control;
Point pt = this.Control.PointToClient(new Point(de.X, de.Y));
if (!control.DisplayRectangle.Contains(pt))
{
de.Effect = DragDropEffects.None;
}
else
{
XTabPageDesigner selectedTabPageDesigner = this.GetSelectedTabPageDesigner();
if (selectedTabPageDesigner != null)
{
selectedTabPageDesigner.OnDragOverInternal(de);
}
}
}
else
{
base.OnDragOver(de);
}
}
private void OnGotFocus(object sender, EventArgs e)
{
}
private void OnRemove(object sender, EventArgs e)
{
}
private void OnSelectionChanged(object sender, EventArgs e)
{
ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService));
this.tabControlSelected = false;
if (service != null)
{
ICollection selectedComponents = service.GetSelectedComponents();
XTabControl control = base.Component as XTabControl;
if (control != null)
{
foreach (object obj2 in selectedComponents)
{
if (obj2 == control)
{
this.tabControlSelected = true;
}
XTabPage tabPageOfComponent = GetTabPageOfComponent(obj2);
if ((tabPageOfComponent != null) && (tabPageOfComponent.Parent == control))
{
this.tabControlSelected = false;
control.SelectedTab = tabPageOfComponent;
break;
}
}
}
}
}
private void OnTabSelectedIndexChanged(object sender, EventArgs e)
{
ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService));
if (service != null)
{
ICollection selectedComponents = service.GetSelectedComponents();
XTabControl component = (XTabControl) base.Component;
bool flag = false;
foreach (object obj2 in selectedComponents)
{
XTabPage tabPageOfComponent = GetTabPageOfComponent(obj2);
if (((tabPageOfComponent != null) && (tabPageOfComponent.Parent == component)) && (tabPageOfComponent == component.SelectedTab))
{
flag = true;
break;
}
}
if (!flag)
{
service.SetSelectedComponents(new object[] { base.Component });
}
}
}
public override DesignerVerbCollection Verbs
{
get
{
if (this.verbs == null)
{
this.removeVerb = new DesignerVerb("移除Tab", new EventHandler(this.OnRemove));
this.verbs = new DesignerVerbCollection();
this.verbs.Add(new DesignerVerb("添加Tab", new EventHandler(this.OnAdd)));
this.verbs.Add(this.removeVerb);
}
if (this.Control != null)
{
this.removeVerb.Enabled = this.Control.Controls.get_Count() > 0;
}
return this.verbs;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -