?? dxmutgui.cs
字號:
case System.Windows.Forms.Keys.Left:
case System.Windows.Forms.Keys.Up:
if (controlFocus != null)
{
OnCycleFocus(false);
return true;
}
break;
case System.Windows.Forms.Keys.Tab:
if (controlFocus == null)
{
FocusDefaultControl();
}
else
{
bool shiftDown = NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ShiftKey);
OnCycleFocus(!shiftDown);
}
return true;
}
}
}
break;
// Mouse messages
case NativeMethods.WindowMessage.MouseMove:
case NativeMethods.WindowMessage.MouseWheel:
case NativeMethods.WindowMessage.LeftButtonUp:
case NativeMethods.WindowMessage.LeftButtonDown:
case NativeMethods.WindowMessage.LeftButtonDoubleClick:
case NativeMethods.WindowMessage.RightButtonUp:
case NativeMethods.WindowMessage.RightButtonDown:
case NativeMethods.WindowMessage.RightButtonDoubleClick:
case NativeMethods.WindowMessage.MiddleButtonUp:
case NativeMethods.WindowMessage.MiddleButtonDown:
case NativeMethods.WindowMessage.MiddleButtonDoubleClick:
case NativeMethods.WindowMessage.XButtonUp:
case NativeMethods.WindowMessage.XButtonDown:
case NativeMethods.WindowMessage.XButtonDoubleClick:
{
// If not accepting mouse input, return false to indicate the message should still
// be handled by the application (usually to move the camera).
if (!usingMouseInput)
return false;
// Current mouse position
short mouseX = NativeMethods.LoWord((uint)lParam.ToInt32());
short mouseY = NativeMethods.HiWord((uint)lParam.ToInt32());
System.Drawing.Point mousePoint = new System.Drawing.Point(mouseX, mouseY);
// Offset mouse point
mousePoint.X -= dialogX;
mousePoint.Y -= dialogY;
// If caption is enabled, offset the Y coordinate by the negative of its height.
if (hasCaption)
mousePoint.Y -= captionHeight;
// If a control is in focus, it belongs to this dialog, and it's enabled, then give
// it the first chance at handling the message.
if (controlFocus != null &&
controlFocus.Parent == this &&
controlFocus.IsEnabled)
{
// If the control MsgProc handles it, then we don't.
if (controlFocus.HandleMouse(msg, mousePoint, wParam, lParam))
return true;
}
// Not yet handled, see if the mouse is over any controls
Control control = GetControlAtPoint(mousePoint);
if ((control != null) && (control.IsEnabled))
{
// Let the control handle the mouse if it wants (and return true if it handles it)
if (control.HandleMouse(msg, mousePoint, wParam, lParam))
return true;
}
else
{
// Mouse not over any controls in this dialog, if there was a control
// which had focus it just lost it
if (msg == NativeMethods.WindowMessage.LeftButtonDown &&
controlFocus != null &&
controlFocus.Parent == this)
{
controlFocus.OnFocusOut();
controlFocus = null;
}
}
// Still not handled, hand this off to the dialog. Return false to indicate the
// message should still be handled by the application (usually to move the camera).
switch(msg)
{
case NativeMethods.WindowMessage.MouseMove:
OnMouseMove(mousePoint);
return false;
}
}
break;
}
// Didn't handle this message
return false;
}
/// <summary>
/// Handle mouse moves
/// </summary>
private void OnMouseMove(System.Drawing.Point pt)
{
// If the mouse was previously hovering over a control, it's either
// still over the control or has left
if (controlMouseDown != null)
{
// If another dialog owns this control then let that dialog handle it
if (controlMouseDown.Parent != this )
return;
// If the same control is still under the mouse, nothing needs to be done
if (controlMouseDown.ContainsPoint(pt))
return;
// Mouse has moved outside the control, notify the control and continue
controlMouseDown.OnMouseExit();
controlMouseDown = null;
}
// Figure out which control the mouse is over now
Control control = GetControlAtPoint(pt);
if (control != null)
{
controlMouseDown = control;
controlMouseDown.OnMouseEnter();
}
}
#endregion
#region Focus
/// <summary>
/// Request that this control has focus
/// </summary>
public static void RequestFocus(Control control)
{
if (controlFocus == control)
return; // Already does
if (!control.CanHaveFocus)
return; // Can't have focus
if (controlFocus != null)
controlFocus.OnFocusOut();
// Set the control focus now
control.OnFocusIn();
controlFocus = control;
}
/// <summary>
/// Clears focus of the dialog
/// </summary>
public static void ClearFocus()
{
if (controlFocus != null)
{
controlFocus.OnFocusOut();
controlFocus = null;
}
}
/// <summary>
/// Cycles focus to the next available control
/// </summary>
private void OnCycleFocus(bool forward)
{
// This should only be handled by the dialog which owns the focused control, and
// only if a control currently has focus
if (controlFocus == null || controlFocus.Parent != this )
return;
Control control = controlFocus;
// Go through a bunch of controls
for (int i = 0; i < 0xffff; i++)
{
control = (forward) ? GetNextControl(control) : GetPreviousControl(control);
// If we've gone in a full circle, focus won't change
if (control == controlFocus)
return;
// If the dialog accepts keybord input and the control can have focus then
// move focus
if (control.Parent.IsUsingKeyboardInput && control.CanHaveFocus)
{
controlFocus.OnFocusOut();
controlFocus = control;
controlFocus.OnFocusIn();
return;
}
}
throw new InvalidOperationException("Multiple dialogs are improperly chained together.");
}
/// <summary>
/// Gets the next control
/// </summary>
private static Control GetNextControl(Control control)
{
int index = (int)control.index + 1;
Dialog dialog = control.Parent;
// Cycle through dialogs in the loop to find the next control. Note
// that if only one control exists in all looped dialogs it will
// be the returned 'next' control.
while (index >= (int)dialog.controlList.Count)
{
dialog = dialog.nextDialog;
index = 0;
}
return dialog.controlList[index] as Control;
}
/// <summary>
/// Gets the previous control
/// </summary>
private static Control GetPreviousControl(Control control)
{
int index = (int)control.index - 1;
Dialog dialog = control.Parent;
// Cycle through dialogs in the loop to find the next control. Note
// that if only one control exists in all looped dialogs it will
// be the returned 'previous' control.
while (index < 0)
{
dialog = dialog.prevDialog;
if (dialog == null)
dialog = control.Parent;
index = dialog.controlList.Count - 1;
}
return dialog.controlList[index] as Control;
}
/// <summary>
/// Sets focus to the default control of a dialog
/// </summary>
private void FocusDefaultControl()
{
// Check for a default control in this dialog
foreach(Control c in controlList)
{
if (c.isDefault)
{
// Remove focus from the current control
ClearFocus();
// Give focus to the default control
controlFocus = c;
controlFocus.OnFocusIn();
return;
}
}
}
#endregion
#region Controls Methods/Properties
/// <summary>Sets the control enabled property</summary>
public void SetControlEnable(int id, bool isenabled)
{
Control c = GetControl(id);
if (c == null)
return; // No control to set
c.IsEnabled = isenabled;
}
/// <summary>Gets the control enabled property</summary>
public bool GetControlEnable(int id)
{
Control c = GetControl(id);
if (c == null)
return false; // No control to get
return c.IsEnabled;
}
/// <summary>Returns the control located at a point (if one exists)</summary>
public Control GetControlAtPoint(System.Drawing.Point pt)
{
foreach(Control c in controlList)
{
if (c == null)
continue;
if (c.IsEnabled && c.IsVisible && c.ContainsPoint(pt))
return c;
}
return null;
}
/// <summary>Returns the control located at this index(if one exists)</summary>
public Control GetControl(int id)
{
foreach(Control c in controlList)
{
if (c == null)
continue;
if (c.ID == id)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -