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

Declaration
function ShowContextMenuByFile(FileName: String): Boolean;  

Description
The ShowContextMenuByFile method executes the shell context menu for the file specified in the FileName parameter (current value of the FileName property does not matter). The menu will appears at current mouse position.  
 
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  
        if ListView1.ReadOnly then  
          MenuOptions := MenuOptions - [moCanRename]  
        else  
          MenuOptions := MenuOptions + [moCanRename];  
 
        ShowContextMenuByFile(ListItem.Caption);  
       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;  
ShowContextMenu method.