Leadtools.Annotations Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
ShowObjectContextMenu Method
See Also  Example
Leadtools.Annotations Namespace > AnnAutomation Class : ShowObjectContextMenu Method



pos
Specifies the location at which the menu should be displayed.
pos
Specifies the location at which the menu should be displayed.
Displays the object context menu.

Syntax

Visual Basic (Declaration) 
Public Overridable Sub ShowObjectContextMenu( _
   ByVal pos As Point _
) 
Visual Basic (Usage)Copy Code
Dim instance As AnnAutomation
Dim pos As Point
 
instance.ShowObjectContextMenu(pos)
C# 
public virtual void ShowObjectContextMenu( 
   Point pos
)
C++/CLI 
public:
virtual void ShowObjectContextMenu( 
   Point pos
) 

Parameters

pos
Specifies the location at which the menu should be displayed.

Example

This example shows the object context menu

Visual BasicCopy Code
Public Sub AnnAutomation_ShowObjectContextMenu(ByVal automation As AnnAutomation)
   ' first add a new object to the automation
   Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
   rectObj.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
   rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
   rectObj.Brush = New AnnSolidBrush(Color.Yellow)
   automation.Container.Objects.Add(rectObj)
   automation.Viewer.Invalidate(rectObj.InvalidRectangle)
   ' make sure no objects are selected in the automation
   automation.SelectNone()

   ' show the object context menu (this should show a message informing you that no objects are currently selected (bring edited)
   ShowContextMenu(automation)

   ' select (edit) the object we have just added
   automation.StartEditing(rectObj, False)

   ' show the object context menu (should show the object context menu)
   ShowContextMenu(automation)
End Sub

Private Sub ShowContextMenu(ByVal automation As AnnAutomation)
   ' check if we can show the context menu
   If automation.CanShowObjectContextMenu Then
      ' use the right-bottom position of the object invalid rectangle as the position of the menu
      Dim rc As Rectangle = automation.CurrentEditObject.InvalidRectangle
      Dim pos As Point = New Point(rc.Right, rc.Bottom)
      automation.ShowObjectContextMenu(pos)
   Else
      MessageBox.Show("Cannot show the object context menu because no object is currently being edited (selected)")
   End If
End Sub
C#Copy Code
public void AnnAutomation_ShowObjectContextMenu(AnnAutomation automation) 

   // first add a new object to the automation 
   AnnRectangleObject rectObj = new AnnRectangleObject(); 
   rectObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel); 
   rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel)); 
   rectObj.Brush = new AnnSolidBrush(Color.Yellow); 
   automation.Container.Objects.Add(rectObj); 
   automation.Viewer.Invalidate(rectObj.InvalidRectangle); 
   // make sure no objects are selected in the automation 
   automation.SelectNone(); 
 
   // show the object context menu (this should show a message informing you that no objects are currently selected (bring edited) 
   ShowContextMenu(automation); 
 
   // select (edit) the object we have just added 
   automation.StartEditing(rectObj, false); 
 
   // show the object context menu (should show the object context menu) 
   ShowContextMenu(automation); 

 
private void ShowContextMenu(AnnAutomation automation) 

   // check if we can show the context menu 
   if(automation.CanShowObjectContextMenu) 
   { 
      // use the right-bottom position of the object invalid rectangle as the position of the menu 
      Rectangle rc = automation.CurrentEditObject.InvalidRectangle; 
      Point pos = new Point(rc.Right, rc.Bottom); 
      automation.ShowObjectContextMenu(pos); 
   } 
   else 
      MessageBox.Show("Cannot show the object context menu because no object is currently being edited (selected)"); 
}

Remarks

Call the CanShowObjectContextMenu property to determine whether the object context menu can be displayed at this time. The context menu used is the AnnAutomationObject.ContextMenu for the object type currently bring edited. If the value of AnnAutomationObject.ContextMenu is null (Nothing in Visual Basic), this method will not do anything.

This AnnAutomation will call this method when the user right-clicks the mouse cursor over the currently selected (edited) object. If the user clicks outside any selected objects, the ShowContextMenu method will be called instead. You can call this method to display this context menu manually (for example, as a result from clicking on a certain menu item in your application).

If the AnnAutomationManager.ContextMenu value is null (Nothing in Visual Basic), this method will not do anything.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features