本文整理汇总了C#中Gtk.DrawingArea.GrabFocus方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingArea.GrabFocus方法的具体用法?C# DrawingArea.GrabFocus怎么用?C# DrawingArea.GrabFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gtk.DrawingArea
的用法示例。
在下文中一共展示了DrawingArea.GrabFocus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnMouseDown
protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
{
ctrlKey = (args.Event.State & ModifierType.ControlMask) != 0;
//Store the mouse position.
Point pt = point.ToGdkPoint();
// Grab focus so we can get keystrokes
canvas.GrabFocus ();
if (selection != null)
selection.Dispose ();
selection = PintaCore.Workspace.ActiveDocument.Selection.Clone ();
// A right click allows you to move the text around
if (args.Event.Button == 3)
{
//The user is dragging text with the right mouse button held down, so track the mouse as it moves.
tracking = true;
//Remember the position of the mouse before the text is dragged.
startMouseXY = point;
startClickPoint = clickPoint;
//Change the cursor to indicate that the text is being dragged.
SetCursor(cursor_hand);
return;
}
// The user clicked the left mouse button
if (args.Event.Button == 1)
{
// If the user is [editing or holding down Ctrl] and clicked
//within the text, move the cursor to the click location
if ((is_editing || ctrlKey) && CurrentTextBounds.ContainsCorrect(pt))
{
StartEditing();
//Change the position of the cursor to where the mouse clicked.
TextPosition p = CurrentTextLayout.PointToTextPosition(pt);
CurrentTextEngine.SetCursorPosition(p, true);
//Redraw the text with the new cursor position.
RedrawText(true, true);
return;
}
// We're already editing and the user clicked outside the text,
// commit the user's work, and start a new edit
switch (CurrentTextEngine.State)
{
// We were editing, save and stop
case TextMode.Uncommitted:
StopEditing(true);
break;
// We were editing, but nothing had been
// keyed. Stop editing.
case TextMode.Unchanged:
StopEditing(false);
break;
}
if (ctrlKey)
{
//Go through every UserLayer.
foreach (UserLayer ul in PintaCore.Workspace.ActiveDocument.UserLayers)
{
//Check each UserLayer's editable text boundaries to see if they contain the mouse position.
if (ul.textBounds.ContainsCorrect(pt))
{
//The mouse clicked on editable text.
//Change the current UserLayer to the Layer that contains the text that was clicked on.
PintaCore.Workspace.ActiveDocument.SetCurrentUserLayer(ul);
//The user is editing text now.
is_editing = true;
//Set the cursor in the editable text where the mouse was clicked.
TextPosition p = CurrentTextLayout.PointToTextPosition(pt);
CurrentTextEngine.SetCursorPosition(p, true);
//Redraw the editable text with the cursor.
RedrawText(true, true);
//Don't check any more UserLayers - stop at the first UserLayer that has editable text containing the mouse position.
return;
}
}
}
else
{
if (CurrentTextEngine.State == TextMode.NotFinalized)
{
//The user is making a new text and the old text hasn't been finalized yet.
FinalizeText();
}
//.........这里部分代码省略.........