Topic: MessageBox (or MessageDlg) Placement

Hello All,
I have an application (see attachment) whose main form (Form1) can be moved anywhere around the screen (top, bottom, right, left) depending on what else I'm doing.
I like to keep all my other forms centred on the main form and do this using

form2.position := pomainformcenter

etc etc.
However, any messagebox (or messagedlg) that pops up (for example, when deleting a record or confirming exit) is always centred on the whole screen and not on the main form (Form 1) - see Screenshot 2 in the attachment.
What I'd like is for any messagebox or messagedlg to also be centred on the main form (see Screenshot 3).
I know I can always write my own messagebox but I was just wondering if it can be done using the standard messagebox
Does anyone have any ideas?
(Using MVD 6.5 and Windows 10).
Thanks,
Derek

Post's attachments

Attachment icon message box position.zip 1.42 mb, 37 downloads since 2026-07-23 

Re: MessageBox (or MessageDlg) Placement

Hi Derek


It's impossible to create such a display for this function in MVD. You need to create your own window.

Re: MessageBox (or MessageDlg) Placement

Hi Sparrow,
Thanks for the quick answer.
I suspected it wasn't possible but just wanted to check if there was something I might have missed.
Derek.

4 (edited by Destiny 2026-07-24 08:11:09)

Re: MessageBox (or MessageDlg) Placement

Hi Derek, hi Sparrow, maybe this one would be suitable.

Post's attachments

Attachment icon message box position.zip 340.75 kb, 37 downloads since 2026-07-24 

Destiny

Re: MessageBox (or MessageDlg) Placement

Hi Destiny


Yes, that's correct. I've made some minor adjustments to the code to make it work correctly.

procedure centered (Sender: TObject; Action: string);
begin
  form2.position := pomainformcenter;
  form3.position := pomainformcenter;
  form4.position := pomainformcenter;
  ConfirmDlg.position := pomainformcenter;
end;

procedure closeform(Sender: TObject; var CloseForm: Boolean);
//procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
    if ConfirmDialog('Warning! Please confirm', 'Please Confirm') then
    begin
        showmessage('confirmed');
    end else CloseForm := False;
end;

procedure ConfirmDlg_btConfirm_OnClick (Sender: TObject; var Cancel: boolean);
begin
    ConfirmDlg.Tag := 1;
end;

function ConfirmDialog(msg, title: String): Boolean;
begin
    ConfirmDlg.Caption := title;
    ConfirmDlg.Tag := 0;
    ConfirmDlg.btConfirm.Cancel := False;
    ConfirmDlg.cMsg.Caption := msg;
    ConfirmDlg.ShowModal;
    result := ConfirmDlg.Tag <> 0;
end;


begin
  form1.menu := nil;
  form1.onclosequery := @closeform;
end.

Re: MessageBox (or MessageDlg) Placement

Indeed, the code is simplified. I removed the confirmation code (showmessage('confirmed');) because it doesn't display in the center of Form1 as Derek wanted; the rest is perfect.

Destiny

Re: MessageBox (or MessageDlg) Placement

Привіт Sparrow, Salut Destiny,
Thank you both for your help.  Everything is now behaving as I like it to.
Derek.

Re: MessageBox (or MessageDlg) Placement

My pleasure

Post's attachments

Attachment icon 4.gif 19.28 kb, 9 downloads since 2026-07-24 

Destiny

Re: MessageBox (or MessageDlg) Placement

Hi Derek


I remembered another example from Dmitry.


https://myvisualdatabase.com/forum/view … 242#p12242

Re: MessageBox (or MessageDlg) Placement

Hello again, Derek.


After reading a bit and scratching my head, it turned out that something could be done with the window. )))
It's not a standard solution, but it's possible.


The hardest part will be centering it in your window. But you can adjust it.
Whether you draw the dialog box yourself or use this solution, the choice is yours.

Post's attachments

Attachment icon message box pos shift.zip 111.16 kb, 44 downloads since 2026-07-24 

Re: MessageBox (or MessageDlg) Placement

Hello Sparrow,
That a nice bit of code there! 
For the specific program I'm working on at the moment, I'll probably go with a bespoke panel (as discussed earlier) but for other applications, I can see me using your option quite a bit (messages that are way off centre are a big annoyance for me sad).
And the great thing is that (apart from quick adjustments to get it properly centred), your code can just be copied and pasted straight into a script - no name changes, field name changes etc. 
Thanks as always for your interest.
Derek.