?? windowdetailcaption.cs
字號:
if (!IsDisposed)
{
// Left mouse down begins a redocking action
if (e.Button == MouseButtons.Left)
{
if (this.ParentWindow.RedockAllowed)
{
WindowContent wc = this.ParentWindow as WindowContent;
// Is our parent a WindowContent instance?
if (wc != null)
{
// Start redocking activity for the whole WindowContent
_redocker = new RedockerContent(this, wc, new Point(e.X, e.Y));
}
}
}
this.Focus();
}
base.OnMouseDown(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
// The double click event will cause the control to be destroyed as
// the Contents are restored to their alternative positions, so need to
// double check the control is not already dead
if (!IsDisposed)
{
// Redocker object needs mouse movements
if (_redocker != null)
_redocker.OnMouseMove(e);
}
base.OnMouseMove(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
// The double click event will cause the control to be destroyed as
// the Contents are restored to their alternative positions, so need to
// double check the control is not already dead
if (!IsDisposed)
{
// Are we currently in a redocking state?
if (_redocker != null)
{
// Let the redocker finish off
_redocker.OnMouseUp(e);
// No longer need the object
_redocker = null;
}
// Right mouse button can generate a Context event
if (e.Button == MouseButtons.Right)
{
// Get screen coordinates of the mouse
Point pt = this.PointToScreen(new Point(e.X, e.Y));
// Box to transfer as parameter
OnContext(pt);
}
}
base.OnMouseUp(e);
}
protected override void OnResize(EventArgs e)
{
// Any resize of control should redraw all of it
Invalidate();
base.OnResize(e);
}
protected virtual void DefineButtonRemapping() {}
protected virtual void OnAddMaximizeInterface() {}
protected virtual void OnRemoveMaximizeInterface() {}
protected virtual void UpdateMaximizeImage() {}
protected virtual void UpdateAutoHideImage() {}
protected virtual void RecalculateButtons() {}
protected virtual void CreateButtons()
{
// Attach events to button
if (_closeButton != null)
{
_closeButton.Click += new EventHandler(OnButtonClose);
_closeButton.GotFocus += new EventHandler(OnButtonGotFocus);
}
if (_hideButton != null)
{
_hideButton.Click += new EventHandler(OnButtonHide);
_hideButton.GotFocus += new EventHandler(OnButtonGotFocus);
}
}
public bool PreFilterMessage(ref Message m)
{
// Has a key been pressed?
if (m.Msg == (int)Win32.Msgs.WM_KEYDOWN)
{
// Is it the ESCAPE key?
if ((int)m.WParam == (int)Win32.VirtualKeys.VK_ESCAPE)
{
// Are we in redocking mode?
if (_redocker != null)
{
// Cancel the redocking activity
_redocker.QuitTrackingMode(null);
// No longer need the object
_redocker = null;
return true;
}
}
}
return false;
}
}
[ToolboxItem(false)]
public class WindowDetailCaptionPlain : WindowDetailCaption
{
protected enum ImageIndex
{
Close = 0,
EnabledHorizontalMax = 1,
EnabledHorizontalMin = 2,
EnabledVerticalMax = 3,
EnabledVerticalMin = 4,
AutoHide = 5,
AutoShow = 6
}
// Class constants
protected const int _inset = 3;
protected const int _offset = 5;
protected const int _fixedLength = 14;
protected const int _imageWidth = 10;
protected const int _imageHeight = 10;
protected const int _buttonWidth = 12;
protected const int _buttonHeight = 12;
protected const int _insetButton = 2;
// Instance fields
protected bool _dockLeft;
protected int _buttonOffset;
static WindowDetailCaptionPlain()
{
// Create a strip of images by loading an embedded bitmap resource
_images = ResourceHelper.LoadBitmapStrip(Type.GetType("Crownwood.Magic.Docking.WindowDetailCaptionPlain"),
"Crownwood.Magic.Resources.ImagesCaptionPlain.bmp",
new Size(_imageWidth, _imageHeight),
new Point(0,0));
}
public WindowDetailCaptionPlain(DockingManager manager,
EventHandler closeHandler,
EventHandler restoreHandler,
EventHandler invertAutoHideHandler,
ContextHandler contextHandler)
: base(manager,
new Size(_fixedLength, _fixedLength),
closeHandler,
restoreHandler,
invertAutoHideHandler,
contextHandler)
{
// Default to thinking we are docked on a left edge
_dockLeft = true;
// Modify painting to prevent overwriting the button control
_buttonOffset = 1 + (_buttonWidth + _insetButton) * 2;
}
public override void ParentStateChanged(State newState)
{
// Should we dock to the left or top of our container?
switch(newState)
{
case State.DockTop:
case State.DockBottom:
_dockLeft = true;
break;
case State.Floating:
case State.DockLeft:
case State.DockRight:
_dockLeft = false;
break;
}
// Ignore the AutoHide feature when in floating form
_ignoreHideButton = (_parentWindow.State == State.Floating);
RecalculateButtons();
}
public override void RemovedFromParent(Window parent)
{
if (parent != null)
{
if (this.Dock != DockStyle.None)
{
Size minSize = parent.MinimalSize;
if (this.Dock == DockStyle.Left)
{
// Remove our width from the minimum size of the parent
minSize.Width -= _fixedLength;
}
else
{
// Remove our height from the minimum size of the parent
minSize.Height -= _fixedLength;
}
parent.MinimalSize = minSize;
}
}
}
public override void AddedToParent(Window parent)
{
if (parent != null)
{
if (this.Dock != DockStyle.None)
{
Size minSize = parent.MinimalSize;
if (this.Dock == DockStyle.Left)
{
// Add our width from the minimum size of the parent
minSize.Width += _fixedLength;
}
else
{
// Add our height from the minimum size of the parent
minSize.Height += _fixedLength;
}
parent.MinimalSize = minSize;
}
}
}
protected override void DefineButtonRemapping()
{
// Define use of current system colors
ColorMap activeMap = new ColorMap();
ColorMap inactiveMap = new ColorMap();
activeMap.OldColor = Color.Black;
activeMap.NewColor = _manager.InactiveTextColor;
inactiveMap.OldColor = Color.Black;
inactiveMap.NewColor = Color.FromArgb(128, _manager.InactiveTextColor);
// Create remap attributes for use by button
_activeAttr.SetRemapTable(new ColorMap[]{activeMap}, ColorAdjustType.Bitmap);
_inactiveAttr.SetRemapTable(new ColorMap[]{inactiveMap}, ColorAdjustType.Bitmap);
}
protected override void OnAddMaximizeInterface()
{
if (_maxButton != null)
{
_maxButton.Size = new Size(_buttonWidth, _buttonHeight);
// Shows border all the time and not just when mouse is over control
_maxButton.PopupStyle = false;
// Define the fixed remapping
_maxButton.ImageAttributes = _inactiveAttr;
// Reduce the lines drawing
_buttonOffset += (_buttonWidth + _insetButton);
}
}
protected override void OnRemoveMaximizeInterface()
{
// Reduce the lines drawing
_buttonOffset -= (_buttonWidth + _insetButton);
}
protected override void CreateButtons()
{
// Define the ImageList and which ImageIndex to show initially
_closeButton = new InertButton(_images, (int)ImageIndex.Close);
_hideButton = new InertButton(_images, (int)ImageIndex.AutoHide);
_closeButton.Size = new Size(_buttonWidth, _buttonHeight);
_hideButton.Size = new Size(_buttonWidth, _buttonHeight);
// Shows border all the time and not just when mouse is over control
_closeButton.PopupStyle = false;
_hideButton.PopupStyle = false;
// Define the fixed remapping
_closeButton.ImageAttributes = _activeAttr;
_hideButton.ImageAttributes = _activeAttr;
// Add to the display
Controls.Add(_closeButton);
Controls.Add(_hideButton);
// Let base class perform common actions
base.CreateButtons();
}
protected override void UpdateAutoHideImage()
{
if (_pinnedImage)
_hideButton.ImageIndexEnabled = (int)ImageIndex.AutoShow;
else
_hideButton.ImageIndexEnabled = (int)ImageIndex.AutoHide;
}
protected override void UpdateMaximizeImage()
{
if (_showCloseButton)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -