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, 104 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, 105 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, 41 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, 113 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.

12 (edited by sparrow 2026-10-30 14:20:51)

Re: MessageBox (or MessageDlg) Placement

Hi Derek


I’ve tinkered with this a bit. I hope it proves useful to you and others.
Take a look at the example; you can incorporate the code into your own program.
There’s a description included in the script.
If you find any errors or have any suggestions, please let me know.

Post's attachments

Attachment icon my mess.zip 109.8 kb, 33 downloads since 2026-10-30 

Re: MessageBox (or MessageDlg) Placement

Hi Sparrow,
Done a bit of testing and it all looks to be working correctly,  I'll go through the code and try and follow everything that's going on but there's a lot of stuff in there that's quite new to me.
Nice option to be able to centre on the screen or the main form too.
Thanks,
Derek.

Re: MessageBox (or MessageDlg) Placement

Привіт Дерек )


With a single `mbOk` button, the function will behave like `ShowMessage`, but with additional features—specifically, centering and positioning relative to the form. In this case, the button code returned can be ignored. I can add comments to the script if you’d like.
I will soon release an updated version of Sudoku with new features.

Re: MessageBox (or MessageDlg) Placement

Hi Derek


This version allows message text to be displayed individually, centered within each active window. For example, if the main window (Form1) is open in the top-left corner and you have moved a newly opened window (Form2) to the right, the message will appear centered within Form2. This is a change from the previous version. The script includes comments. Translated via Google Translate.

Post's attachments

Attachment icon my mess 1.zip 112.39 kb, 30 downloads since 2026-11-05 

Re: MessageBox (or MessageDlg) Placement

Hi Sparrow,
Having message dialogues centred on the form to which they relate is a great feature (the way that the standard message dialogue simply pops up in the middle of the screen rather than centred on the appropriate form has always been an annoyance for me).
Thanks for the update and improvements.
Derek.