?? autohidepanel.cs
字號:
rect.Width = (_slideRect.Width + barSize.Width) /
_slideSteps * (_slideStep + 1);
// Want the right hand side of WCT showing
_currentWCT.Location = new Point(rect.Width - _currentWCT.Width - barSize.Width, 0);
break;
case DockStyle.Right:
int right = _currentPanel.Right;
if (lastStep)
rect.Width = _slideRect.Width + barSize.Width;
else
rect.Width = (_slideRect.Width + barSize.Width) /
_slideSteps * (_slideStep + 1);
rect.X -= rect.Right - right;
_currentWCT.Location = new Point(barSize.Width, 0);
break;
case DockStyle.Top:
if (lastStep)
rect.Height = _slideRect.Height + barSize.Height;
else
rect.Height = (_slideRect.Height + barSize.Height) /
_slideSteps * (_slideStep + 1);
// Want the bottom of the WCT showing
_currentWCT.Location = new Point(0, rect.Height - _currentWCT.Height - barSize.Height);
break;
case DockStyle.Bottom:
int bottom = _currentPanel.Bottom;
if (lastStep)
rect.Height = _slideRect.Height + barSize.Height;
else
rect.Height = (_slideRect.Height + barSize.Height) /
_slideSteps * (_slideStep + 1);
rect.Y -= rect.Bottom - bottom;
_currentWCT.Location = new Point(0, barSize.Height);
break;
}
// Have to use Win32 API call to alter the Panel size and position at the same time, no
// Control method/property is available to do both at the same time. Otherwise you can see
// the Panel being moved in two steps which looks naff!
User32.MoveWindow(_currentPanel.Handle, rect.Left, rect.Top, rect.Width, rect.Height, true);
// Stop timer when all required steps performed
if (lastStep)
{
StopSlideTimer();
// If sliding into view from bottom
if (this.Dock == DockStyle.Top)
{
// Must cause repaint to prevent artifacts
_currentPanel.Refresh();
}
}
}
else
{
int steps = _slideSteps - _slideStep;
// Move Window another step towards required position
switch(this.Dock)
{
case DockStyle.Left:
if (lastStep)
rect.Width = 0;
else
rect.Width = (_slideRect.Width + barSize.Width) /
_slideSteps * steps;
break;
case DockStyle.Right:
int right = _currentPanel.Right;
if (lastStep)
rect.Width = 0;
else
rect.Width = (_slideRect.Width + barSize.Width) /
_slideSteps * steps;
rect.X += right - rect.Right;
break;
case DockStyle.Top:
if (lastStep)
rect.Height = 0;
else
rect.Height = (_slideRect.Height + barSize.Height) /
_slideSteps * steps;
break;
case DockStyle.Bottom:
int bottom = _currentPanel.Bottom;
if (lastStep)
rect.Height = 0;
else
rect.Height = (_slideRect.Height + barSize.Height) /
_slideSteps * steps;
rect.Y += bottom - rect.Bottom;
break;
}
// Have to use Win32 API call to alter the Panel size and position at the same time, no
// Control method/property is available to do both at the same time. Otherwise you can see
// the Panel being moved in two steps which looks naff!
User32.MoveWindow(_currentPanel.Handle, rect.Left, rect.Top, rect.Width, rect.Height, true);
// Stop timer when all required steps performed
if (lastStep)
{
StopSlideTimer();
// No longer need to show it
RemoveDisplayedWindow();
// No longer considered the shown window
_currentWCT = null;
}
}
// Increment the step value
_slideStep++;
}
}
protected void OnDismissTick(object sender, EventArgs e)
{
// Safety check that timer does not expire after our death
if (this.IsDisposed || (_currentPanel == null) || _currentPanel.IsDisposed)
{
StopDismissTimer();
return;
}
// Should any dismiss attempt from timer be ignored?
if (!_ignoreDismiss)
{
// Are we currently showing a Window?
if (_currentPanel != null)
{
// Timer is being used to hide the Panel
_slideOut = false;
// Kick off the timer
StartSlideTimer();
}
}
// Stop the dismiss timer from reoccuring
StopDismissTimer();
}
protected void OnContainerResized(object sender, EventArgs e)
{
RemoveShowingWindow();
}
public void RemoveShowingWindow()
{
_ignoreDismiss = false;
// Is focus leaving the entire WindowContentTabbed control?
if (_currentWCT != null)
{
// Remember current focus
IntPtr hWnd = User32.GetFocus();
// Do not slide a window in the process of being removed
StopDismissTimer();
StopSlideTimer();
// Remove Panel/WCT from display and stop timers
RemoveDisplayedWindow();
// No longer considered the shown window
_currentWCT = null;
// Replace the focus
User32.SetFocus(hWnd);
}
// Prevent drawing artifacts by invalidating window
Invalidate();
}
protected void OnPanelEnter(object sender, EventArgs e)
{
_ignoreDismiss = true;
}
protected void OnPanelLeave(object sender, EventArgs e)
{
_ignoreDismiss = false;
// Is focus leaving the entire WindowContentTabbed control?
if (!_killing && (_currentWCT != null) && !_currentWCT.ContainsFocus)
{
// Remember current focus
IntPtr hWnd = User32.GetFocus();
// Do not slide a window in the process of being removed
StopDismissTimer();
StopSlideTimer();
// Remove Panel/WCT from display and stop timers
RemoveDisplayedWindow();
// No longer considered the shown window
_currentWCT = null;
// Replace the focus
User32.SetFocus(hWnd);
}
}
protected void MonitorPanel(bool add)
{
MonitorControl(_currentPanel, add);
}
protected void MonitorControl(Control c, bool add)
{
if (add)
{
// Monitor focus changes on the Control
c.GotFocus += new EventHandler(OnPanelEnter);
c.LostFocus += new EventHandler(OnPanelLeave);
}
else
{
// Unmonitor focus changes on the Control
c.GotFocus -= new EventHandler(OnPanelEnter);
c.LostFocus -= new EventHandler(OnPanelLeave);
}
foreach(Control child in c.Controls)
MonitorControl(child, add);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
Color backColor = base.BackColor;
if (_manager.Style == VisualStyle.IDE)
{
if (_defaultColor)
backColor = ColorHelper.TabBackgroundFromBaseColor(SystemColors.Control);
else
backColor = ColorHelper.TabBackgroundFromBaseColor(backColor);
}
else
if (_defaultColor)
backColor = SystemColors.Control;
using(SolidBrush brush = new SolidBrush(backColor))
e.Graphics.FillRectangle(brush, this.ClientRectangle);
}
public bool PreFilterMessage(ref Message msg)
{
Form parentForm = this.FindForm();
// Only interested if the Form we are on contains the focus and we are showing a Panel
if ((parentForm != null) && (parentForm == Form.ActiveForm) &&
parentForm.ContainsFocus && (_currentPanel != null) &&
!_currentPanel.IsDisposed)
{
switch(msg.Msg)
{
case (int)Win32.Msgs.WM_MOUSEMOVE:
Win32.POINT screenPos;
screenPos.x = (int)((uint)msg.LParam & 0x0000FFFFU);
screenPos.y = (int)(((uint)msg.LParam & 0xFFFF0000U) >> 16);
// Convert the mouse position to screen coordinates
User32.ClientToScreen(msg.HWnd, ref screenPos);
// Get the screen rectangle for the showing panel and this object
Rectangle panelRect = _currentPanel.RectangleToScreen(_currentPanel.ClientRectangle);
Rectangle thisRect = this.RectangleToScreen(this.ClientRectangle);
// Do we think the mouse is not over the tab or panel?
if (_dismissRunning)
{
// Is mouse moving over the panel?
if (panelRect.Contains(new Point(screenPos.x, screenPos.y)))
{
// Cancel timer
StopDismissTimer();
}
}
else
{
// If mouse not over the Panel or the ourself
if (!panelRect.Contains(new Point(screenPos.x, screenPos.y)) &&
!thisRect.Contains(new Point(screenPos.x, screenPos.y)))
{
// Simulate the mouse leaving ourself so that dismiss timer is started
OnPagesLeave(null);
}
}
break;
}
}
return false;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -