shellproperties ShowContextMenu method
Return to Introduction  Previous page  Next page
Applies to
dcShellProperties component.  

Declaration
function ShowContextMenu: Boolean;  

Description
The ShowContextMenu method executes the shell context menu, for the shell object specified in the FileName property. The popup menu will appears at current mouse position. ShowContextMenu method returns True if succeeed, or False otherwise.  
 
Use MenuOptions property to specify some advanced options for the context menu and MenuAlignment to specify the menu position.  
 
tip You can test this feature at design-time, specifying the FileName property in the Object Inspector and clicking the right mouse button on the component image. In the popup menu select the "Test ShowContextMenu" item.  

Example
procedure TForm1.ListView1MouseDown(Sender: TObject;  
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);  
var  
  ListItem: TListItem;  
begin  
  if Button = mbRight then  
   begin  
    ListItem := ListView1.GetItemAt(X, Y);  
    if ListItem <> nil then  
     begin  
      SetFocus;  
      ListItem.Selected := True;  
 
      with dcShellProperties1 do  
       begin  
        FileName := ListItem.Caption // ?  
 
        if ListView1.ReadOnly then  
          MenuOptions := MenuOptions - [moCanRename]  
        else  
          MenuOptions := MenuOptions + [moCanRename];  
 
        ShowContextMenu;  
       end;  
     end;  
   end;  
end;  
 
procedure TForm1.dcShellProperties1Rename(Sender: TObject;  
  FileName: String);  
begin  
  if ListView1.Selected <> nil then   
    ListView1.Selected.EditCaption;  
end;  

See also
MenuOptions and MenuAlignment properties;  
ShowContextMenuByFile method.  
File not found.