2

我有一个对话框,为用户提供 3 个选项,是、否、取消 ..
我将是、否更改为新标题武器 1 和武器 2。我还更改按钮的宽度以匹配新标题的宽度. 但是如果新的标题太长,按钮就会重叠。我该如何解决这个问题?

  Weapon1 := FMyPlayers.player[FGamePlay.chartoattackwith].Values['Attack1'];
  Range1 :=  FMyPlayers.player[FGamePlay.chartoattackwith].Values['Range1'];
  Weapon2 := FMyPlayers.player[FGamePlay.chartoattackwith].Values['Attack2'];
  Range2 :=  FMyPlayers.player[FGamePlay.chartoattackwith].Values['Range2'];
    with CreateMessageDialog('Please pick a weapon:', mtConfirmation, mbYesNoCancel) do
        try
          TButton(findcomponent('Yes')).Width := self.Canvas.TextWidth('    '+Weapon1+':'+range1+'    ');
          TButton(findcomponent('No')).Width :=  self.Canvas.TextWidth('    '+Weapon2+':'+range2+'    ');
          TButton(FindComponent('Yes')).Caption := Weapon1+':'+range1;
          TButton(FindComponent('No')).Caption := Weapon2+':'+range2;
         case ShowModal of
           mrYes: AttackValue := '1';
           mrNo:  AttackValue := '2';
           mrCancel: exit;
         end;
        finally
       Free;
     end;
4

1 回答 1

3

插入这部分代码

  TButton(findcomponent('No')).Left := TButton(findcomponent('Yes')).Width + TButton(findcomponent('Yes')).Left;
  TButton(findcomponent('Cancel')).Left := TButton(findcomponent('No')).Width + TButton(findcomponent('No')).Left;
  Width := 2*TButton(findcomponent('Yes')).Left + TButton(findcomponent('Cancel')).Left + TButton(findcomponent('Cancel')).Width;

根据大卫赫弗南

var
No,Yes,Cancel:TButton;

.....
No := TButton(findcomponent('No'));
Yes := TButton(findcomponent('Yes'));
Cancel := TButton(findcomponent('Cancel'));

No.Left := Yes.Width + Yes.Left;
Cancel.Left := No.Width + No.Left;
Width := 2 * Yes.Left + Cancel.Left + Cancel.Width;
于 2012-11-19T07:24:18.180 回答