TPopupMenu를 PDF 뷰어에 연결하여 page를 오른쪽 클릭하면 context menu가 나타나도록 합니다property PopupMenu: TPopupMenu; // published, inherited from TControl
PopupMenu를 설정하면 뷰어가 같은 form에 놓인 TPopupMenu component와 연결됩니다. 사용자가 뷰어 안에서 오른쪽 클릭을 하거나 keyboard menu key를 누를 때마다 VCL/LCL이 cursor 위치에 메뉴를 자동으로 보여 주며, application이 직접 WM_CONTEXTMENU를 처리할 필요는 없습니다
일반적인 PDF reader context menu에는 Copy Selected Text, Zoom In, Zoom Out, Fit Width, Rotate, Go to Page…, Find…, Save As… 같은 항목이 있습니다. 메뉴 항목은 보통 CurrentCharIndex, Zoom, FitMode, Rotation, PageNumber 같은 public property를 읽거나 써서 document에 작동합니다
팝업은 OnContextPopup mechanism을 통해 표시되므로, OnContextPopup을 처리하고 Handled := True로 설정해 동적으로 억제하거나 바꿀 수 있습니다. 이는 오른쪽 클릭이 자체 menu가 필요한 form field나 annotation 위에서 발생할 때 유용합니다
TPopupMenu instance에 대한 연결은 form 파일에 component reference로 저장됩니다AllowUserTextSelection이 False여도 나타납니다TPopupMenu.OnPopup을 연결하고 CurrentCharIndex나 Pdf.Active 같은 viewer state를 검사하세요
// Attach a context menu offering Copy / Fit Width / Go to Page
procedure TForm1.FormCreate(Sender: TObject);
begin
PdfView1.PopupMenu := pmReader;
end;
procedure TForm1.miFitWidthClick(Sender: TObject);
begin
PdfView1.FitMode := pfmFitToWidth;
end;
procedure TForm1.miGoToPageClick(Sender: TObject);
var S: string;
begin
S := IntToStr(PdfView1.PageNumber);
if InputQuery('Go to page', 'Page number:', S) then
PdfView1.PageNumber := StrToIntDef(S, PdfView1.PageNumber);
end;