Incus J 10 Posted October 12, 2020 I'd like to calculate the width of a Popup Menu before it is displayed, so that I can position and align it accurately when I call its .Popup(x,y) method. function CalcPopupMenuWidth(popup : TPopupMenu) : single; var i : integer; w : single; item : TMenuItem; begin result := 0; for i := 0 to popup.ItemsCount-1 do begin item := popup.Items[i]; w := popup.Items[i].Width; if w > result then result := w; end; end; The above approach iterates over the individual menu items, to determine the widest item. It almost works, in that it calculates the width correctly, but only after the Popup Menu has been displayed once. If the Popup Menu has never been displayed (yet) then this code always returns a value of 50. I'm guessing maybe that's a default width for a TMenuItem, which gets updated with the actual width shortly before it is displayed. How can I calculate the dimensions of a Popup Menu before displaying it? Share this post Link to post