Solved

Changing the Font Color in a TMessageDlg?

Posted on 1998-07-02
7
256 Views
Last Modified: 2013-12-02
Hi

Is there a way to change the font color in a TMessageDlg, and if so, how??

I am using D1 and WFW 3.11
0
Comment
Question by:jdthedj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1357029
TMessageDlg?? Are you sure there is such thing?

I know there's the MessageDlg function, but not a TMessageDlg type (??)

In the Dialogs unit sources in the CreateMessageDialog body you see the following lines:

    Font.Name := 'MS Sans Serif';
    Font.Height := -11;
    Font.Style := [fsBold];

You can try and recreate it so you add the color definition. You'll have to copy all this function and rewrite this section as you want.
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1357030
Hi Matvey - thanx for replying.  You're quite right it is a function not a type.  I'm experimenting with the Dialogs unit to see what I can come up with.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1357031
I think it's easier to just create your own new form and make it a good-looking dialog. You know how to do that, right? Just place a red-font label on a form and some buttons and there you go...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
Jacco earned 50 total points
ID: 1357032
Matvey is right, but there is a smart way around this and reuse some code of the VCL anyway. Just use the CreateMessageDlg function and adjust the resulting form. (If you alter a lot you can also adjust the Width/Height of the form).

Here is a silly example on how to do it:

function MyMessageDlg(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
var
  iCount : Integer;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
    try
      HelpContext := HelpCtx;
      for iCount:=0 to ComponentCount-1 do begin
        if Components[iCount] is TLabel then begin
          TLabel(Components[iCount]).Font.Color := clRed;
          TLabel(Components[iCount]).Font.Name := 'Times New Roman';
          TLabel(Components[iCount]).Font.Size := 14;
        end;
        if Components[iCount] is TButton then begin
          TButton(Components[iCount]).Font.Color := clBlue;
        end;
      end;
      Result:=ShowModal;
    finally
      Free;
    end;
end;

Regards Jacco
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1357033
The color of the font of the button is not changed this way.

There is one (or no) TImage named "image" (for the icon)
There is one TLabel named "message" (for the text)
There are X buttons named:

'Yes'
'No'
'OK'
'Cancel'
'Abort'
'Retry'
'Ignore'
'All'
'Help'

So you can also use the FindComponent method to find the components and change them.

Example:

function MyMessageDlg(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
var
  iCount : Integer;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons) do
    try
      HelpContext := HelpCtx;
      with TLabel(FindComponent('message')) do begin
        Font.Color := clYellow;
      end;
      if FindComponent('image')<>nil then
        with TImage(FindComponent('image')) do begin
          Left:=0;
          Top:=0;
        end;
      if FindComponent('ok')<>nil then
        with TButton(FindComponent('ok')) do begin
          Caption := 'Go ahead';
        end;
      Result:=ShowModal;
    finally
      Free;
    end;
end;





This way you can even add Buttons
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1357034
I think Borland made the CreateMessageDlg function available public for other units for the purpose of extension.

Regards Jacco
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1357035
Hi Jacco - Thanks for the answer.  I really got sick of the "default" font - it would be better even if it was black, not that sickly "purple" color.

Hi Matvey - Thanks for your further comments.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month6 days, 14 hours left to enroll

623 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