Solved

Help with ShowMessagePos

Posted on 1998-08-29
5
364 Views
Last Modified: 2010-04-03
Could someone give me an example of how to get ShowMessagePos to center itself in the active form.

Thanks
0
Comment
Question by:evel
5 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338123
Why don't you use MessageDlgPos?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338124
Here is an example from Delphi help file =)

procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlgPos('Are you there?',mtConfirmation, mbYesNoCancel, 0, 200, 200);
end;

Regards,
Viktor Ivanov
0
 
LVL 3

Expert Comment

by:vladika
ID: 1338125
All procedures (ShowMessage, MessageDlgPos etc) found on the function CreateMessageDialog
For details see dialogs.pas

So, I wrote procedure ShowMessageCenter.
You can use it instead of ShowMessagePos or you can modify it for your needs.

procedure ShowMessageCenter(const Msg: string);
var R: TRect;
begin
  if not Assigned(Screen.ActiveForm) then ShowMessage(Msg) else
  with CreateMessageDialog(Msg, mtCustom, [mbOK]) do
  try
    GetWindowRect(Screen.ActiveForm.Handle, R);
    Left := R.Left + ((R.Right - R.Left) div 2) - (Width div 2);
    Top := R.Top + ((R.Bottom - R.Top) div 2) - (Height div 2);
    ShowModal;
  finally
    Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessageCenter('I am centered in the active form');
end;


0
 

Author Comment

by:evel
ID: 1338126
Thanks vladika, that's just what I was looking for. Please answer the question so I can give you credit.
0
 
LVL 3

Accepted Solution

by:
vladika earned 100 total points
ID: 1338127
Ok. This is my "official answer".

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 45
can't find the executable in Simulator 1 101
Dev express lookupcombo 3 35
scroll down TListBox component in Delphi 1 19
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question