我需要我的视障用户才能选择字体大小,并且大多数情况下我已经处理好了,但是弹出菜单无法正常工作,因为行高没有随字体大小而改变。
正在使用...
puMenuMain.OwnerDraw:=True;
Screen.MenuFont.Size:=18; // Actually selected from list by User or Helper
对于字体大小来说效果很好,但是行高没有改变。在其他组件(如TDBGrid)中,Font.Size的更改也会更改行高。
如何获得弹出菜单来调整所选Font.Size的行高?
documentation状态的OwnerDraw
的TPopupMenu
属性:
当OwnerDraw为true时,菜单项会收到一个OnMeasureItem和一个需要在屏幕上呈现它们时的OnDrawItem事件。
因此,在设计时或运行时为弹出菜单的OnMeasureItem
分配一个处理程序:
puMenuMain.OwnerDraw:=True;
Screen.MenuFont.Size:=18;
for i := 0 to puMain.Items.Count - 1 do
puMain.Items[i].OnMeasureItem := PopupMeasureItem;
PopupMeasureItem
可以很简单
procedure TMyForm.PopupMeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
Height := ACanvas.TextHeight('.') + 2;
end;
或者您可以确定用户从列表中选择的必要高度,以免每次绘制项目时保存呼叫TextHeight
。
ImageList
组件。Height
属性设置为所需的值。PopupMenu
属性与此ImageList
关联。