Versuch mal das (Allerdings nicht getestet)
Mglw müssen da noch ein paar Pixel dazu !
[EDIT] Überarbeitete Version !
Delphi-Quellcode:
function GetPopUpMenuWidth(PopUpMenu : TPopUpMenu; Canvas : TCanvas) : Integer;
var i : Integer;
LongestCaption : Integer;
begin
LongestCaption := -1;
Result := 0;
for i := 0 to PopUpMenu.Items.Count -1 do
if LongestCaption < length(TMenuItem(PopUpMenu.Items[i]).Caption) then
begin
LongestCaption := length(TMenuItem(PopUpMenu.Items[i]).Caption);
Result := Canvas.TextWidth(TMenuItem(PopUpMenu.Items[i]).Caption );
end;
end;
function GetPopUpMenuHeight(PopUpMenu : TPopUpMenu; Canvas : TCanvas) : Integer;
begin
Result := 0;
if PopUpMenu.Items.Count > 0 then
Result := Canvas.TextHeight(PopUpMenu.Items[0].Caption) + 21 * PopUpMenu.Items.Count;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(Inttostr(GetPopUpMenuWidth(PopUpMenu1,Canvas)));
showmessage(Inttostr(GetPopUpMenuHeight(PopUpMenu1,Canvas)));
end;