2017-11-04 222 views

回答

2

只需添加第二TButton:中Form.ShowModal

function MyYesNoMessageBox: Integer; 
var 
    Form: TSetupForm; 
    YesButton, NoButton: TNewButton; 
    MesssageLabel: TLabel; 
begin 
    Form := CreateCustomForm; 
    Form.BorderStyle := bsDialog; 
    Form.Position := poOwnerFormCenter; 
    Form.ClientWidth := ScaleX(400); 
    Form.ClientHeight := ScaleY(130); 
    Form.Caption := 'Caption'; 

    MesssageLabel := TLabel.Create(Form); 
    MesssageLabel.Parent := Form; 
    MesssageLabel.Left := ScaleX(16); 
    MesssageLabel.Top := ScaleX(16); 
    MesssageLabel.Width := Form.ClientWidth - 2*ScaleX(16); 
    MesssageLabel.Height := ScaleY(32); 
    MesssageLabel.AutoSize := False; 
    MesssageLabel.WordWrap := True; 
    MesssageLabel.Caption := 'Lorem ipsum dolor sit amet, ...'; 

    YesButton := TNewButton.Create(Form); 
    YesButton.Parent := Form; 
    YesButton.Width := ScaleX(80); 
    YesButton.Height := ScaleY(24); 
    YesButton.Left := Form.ClientWidth - 2 * (YesButton.Width + ScaleX(8)); 
    YesButton.Top := Form.ClientHeight - YesButton.Height - ScaleY(8); 
    YesButton.Caption := '&Yes'; 
    YesButton.ModalResult := mrYes; 

    NoButton := TNewButton.Create(Form); 
    NoButton.Parent := Form; 
    NoButton.Width := YesButton.Width; 
    NoButton.Height := YesButton.Height; 
    NoButton.Left := YesButton.Left + YesButton.Width + ScaleX(8); 
    NoButton.Top := YesButton.Top; 
    NoButton.Caption := '&No'; 
    NoButton.ModalResult := mrNo; 

    Result := Form.ShowModal; 
end; 

和測試返回代碼(或檢查Form.ModalResult):

if MyYesNoMessageBox = mrYes then 
begin 
    MsgBox('Yes selected', mbInformation, MB_OK); 
end 
    else 
begin 
    MsgBox('No selected', mbInformation, MB_OK); 
end; 

Custom Yes/No message box

+0

這是消息appering到窗口的中間安裝?我的頭頂上是一片貧瘠。 –

+0

@Pedro對不起,但我不明白。你指的是時間還是地點? –