The latest build of this product (v22.1.3) was released 4 months ago, which was before this thread was created.
Posted 2 months ago by Gavin Huet
Version: 22.1.3
Avatar

Hi,

When raising the MenuRequested event, the event argument SyntaxEditorMenuEventArgs can get the location of the mouse or the menu, but some keyboards have a context menu button that is not handled.

In this case I want to display the context menu wherever the cursor is in the editor, but have been unable to determine the position of the cursor as a Point object.

Example:

If e.HitTestResult IsNot Nothing AndAlso e.HitTestResult.Location <> Nothing Then
  PopupMenu.Popup(SyntaxEditor1.PointToScreen(e.HitTestResult.Location), AddressOf SyntaxEditor1_PopupMenuClick)
ElseIf e.Menu IsNot Nothing AndAlso e.Menu.Location <> Nothing Then
  PopupMenu.Popup(SyntaxEditor1.PointToScreen(e.Menu.Location), AddressOf SyntaxEditor1_PopupMenuClick)
Else
  ' TODO
End If

Is there any way to determine the location of the cursor?

Thanks

Gavin

Comments (2)

Answer - Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Gavin,

You can use "SyntaxEditor.ActiveView.GetCharacterBounds(SyntaxEditor.ActiveView.Selection.CaretOffset)" to get the bounds of the character at the caret. I suggest using the lower-left corner of the character bounds for the menu location. These bounds are relative to the text area of the view, not the control, so those will need to be translated. Use "SyntaxEditor.ActiveView.TransformFromTextArea" to get the client location, and, of course, "SyntaxEditor.PointToScreen" to get final point where the menu will be displayed.

The following sample code is C#, but illustrates the concept and should be easy enough to translate to VB.

var characterBounds = editor.ActiveView.GetCharacterBounds(editor.ActiveView.Selection.CaretOffset);
var textAreaPoint = new Point(characterBounds.Left, characterBounds.Bottom);
var clientPoint = editor.ActiveView.TransformFromTextArea(textAreaPoint); 
var screenPoint = editor.PointToScreen(clientPoint);
// Show popup as ScreenPoint


Actipro Software Support

Posted 2 months ago by Gavin Huet
Avatar

Thanks for the quick reply, that works a treat.

Add Comment

Please log in to a validated account to post comments.