让PageControl的Tab标签响应鼠标右键

在PageControl的OnMouseUp事件中:

void __fastcall TForm1::PageControl1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if (Button == mbRight)
    {
        int nIndex = PageControl1->IndexOfTabAt(X, Y);
        if (nIndex >= 0)
        {
            PageControl1->ActivePageIndex = nIndex;
            TPoint Pos = PageControl1->ClientToScreen(TPoint(X,Y));
            PopupMenu1->Popup(Pos.x, Pos.y);
        }
    }
}

沒有考慮Tab隱藏的情況。
如果要考慮有 Tab 隱藏的情況,需要把 nIndex 轉換為實際的 Index

你可能感兴趣的:(button)