예제 #1
0
    // Called after the tree view control has processed device input.
    private void OnTreeViewInputProcessed(object sender, InputEventArgs eventArgs)
    {
      var treeView = (TreeView)sender;
      var selectedItem = treeView.SelectedItem;
      var inputService = treeView.InputService;

      if (!inputService.IsMouseOrTouchHandled               // Mouse was not handled before?
          && inputService.IsDoubleClick(MouseButtons.Left)  // Double-click detected?
          && selectedItem == _lastSelectedItem              // Both clicks were on the same item?
          && selectedItem != null                           // Any item is selected?
          && selectedItem.IsMouseOver)                      // The mouse is over the selected item?
      {
        // A tree view item was double-clicked. Show a message box with the data of the item.
        // This is only for debugging, so we simply use the Windows Forms MessageBox.
#if WINDOWS
        MessageBox.Show((string)selectedItem.UserData);
#endif
      }

      // Remember the selected item. This is necessary because we must be able to check if both
      // clicks of the double-click were on the same item. When a tree view item is clicked,
      // it is selected. Clicking two different items in rapid succession should not count as
      // a double-click.
      _lastSelectedItem = selectedItem;
    }
예제 #2
0
        //--------------------------------------------------------------
        private void OnScreenInputProcessed(object sender, InputEventArgs eventArgs)
        {
            // Automatically hide the ToolTip if the Screen does not process input (because then
              // we would not see mouse movement, so we close it immediately).
              // Or close it if another UIControl was added on top that could hide the ToolTip.
              if (IsToolTipOpen)
              {
            if (!Screen.InputEnabled                                              // Screen does not handle input.
            || Screen.Children[Screen.Children.Count - 1] != ToolTipControl)  // Another window was opened.
            {
              // ----- Screen was disabled, or another control was shown on top.
              CloseToolTip();
              return;
            }
              }

              var context = eventArgs.Context;
              if (context.MousePositionDelta == Vector2F.Zero)
              {
            // ----- No mouse movement --> Increase counter.
            _noMouseMoveDuration += context.DeltaTime;
              }
              else
              {
            // ----- Mouse moved --> Close tool tip if mouse is no longer over control. Reset counter.
            if (_control == null || !_control.IsMouseOver)
              CloseToolTip();

            _noMouseMoveDuration = TimeSpan.Zero;
            return;
              }

              if (_noMouseMoveDuration >= ToolTipDelay)
              {
            // ----- Mouse was not moving for ToolTipDelay seconds --> Show tool tip.

            // Get control under the mouse cursor. Search up the control hierarchy until we
            // find a control with a tool tip string.
            var control = Screen.ControlUnderMouse;
            while (control != null && control.ToolTip == null)
              control = control.VisualParent;

            if (control != null)
            {
              // Show or update tool tip.
              ShowToolTip(control.ToolTip, context.MousePosition);
              _control = control;
            }

            // We do not want to check on the same position again in the next frame, so we set
            // an extreme value that will be automatically reset when the mouse moves in the future.
            _noMouseMoveDuration = TimeSpan.MinValue;
              }
        }