CreateMessageDialog: draw on Canvas lazarus / 21-General ---------------------------------------------------------------------- Rik · 2025-02-04 10:08 I want to create my own message dialog, with text and background colours at my choice and multiline text with different fonts for each line. My thought was to use CreateMessageDialog, leave the message parameter empty and instead draw the message on the Canvas using TextOut: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   MsgFrm:= CreateMessageDialog('TEST','',mtConfirmation,[mbYes,mbNo]); // MsgFrm: tForm;  try    MsgFrm.Color:= clYellow;    MsgFrm.Font.Color:= clBlue;    MsgFrm.Canvas.TextOut(20,20,'Hello world, here I am');    MsgFrm.ShowModal;  finally    FreeAndNil(MsgFrm);  end; MsgFrm.Canvas.TextOut(20,20,'Hello world, here I am') however seems not to work (the text doesn't appear). Am I doing something wrong or is it just not possible to access the Canvas with CreateMessageDialog? ---------------------------------------------------------------------- ASerge · 2025-02-04 16:19 Quote from: Rik on February 04, 2025, 11:08:37 am...draw the message on the Canvas using TextOut: Am I doing something wrong or is it just not possible to access the Canvas with CreateMessageDialog? Rendering takes place according to the requirements of the OS at any time. No one stores your image between them. In this case, you drew in the void before the window appeared, and then the window drew itself. It must be rendered in the OnPaint event for a form created via CreateMessageDialog. ---------------------------------------------------------------------- madref · 2025-02-04 18:46 why not create a separate form for all your messages. I created a form with a textbox, image and 2 buttons and made it flexible. I did it like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit referee_meldingen;  {$mode objfpc}{$H+}  interface  uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons,  ExtCtrls, ColorSpeedButton;  type  TMsgType = (mGeen, mInfo, mUitroep1, mUitroep2, mStop, mVraag1, mVraag2,              mBuis, mGo, mThink, mSign, mPotlood1, mPotlood2, mPDF, mKrant);  TMsgButton = (bYesNo, bOKCancel, bOK);  type    { TForm_Melding }    TForm_Melding = class(TForm)    Button1: TColorSpeedButton;    Button2: TColorSpeedButton;    Image_Pop: TImage;    Label_Message: TLabel;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormActivate(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);    procedure FormKeyDown(Sender: TObject; var Key: Word);    procedure FormShow(Sender: TObject);  private    { private declarations }    MB: TMsgButton;    Custom: Boolean;     // True -=> MSgCustom.  False -=> Normal message    procedure Show_JuistePop(const MsgT: TMsgType);  public    { public declarations }    procedure Melding (const MsgT: TMsgType; const MsgB: TMsgButton;                       const MsgStr, MsgCaption: string);    procedure Melding_Alleen (const MsgT: TMsgType; const MsgStr, MsgCaption: string);    procedure Melding_Aangepast (const MsgT: TMsgType;                              const MsgStr, MsgCaption: string;                                const Btn1Msg, Btn2Msg: string;                                const Btn1Gnr, Btn2Gnr: integer);  end;  var  Form_Melding: TForm_Melding;  implementation  {$R *.lfm}  uses LCLType,  referee_lint,  referee_types;  { TForm_Melding }  procedure TForm_Melding.Button1Click(Sender: TObject);begin  MessageButtonPressed := 0;  Close;end;    // Button1Click  procedure TForm_Melding.Button2Click(Sender: TObject);begin  MessageButtonPressed := 1;  Close;end;    // Button2Click  procedure TForm_Melding.FormActivate(Sender: TObject);begin               Button1.StateHover.Color := KleurPop + $00A0A000;               Button1.StateHover.BorderColor:= KleurPop;               Button1.StateActive.Color := Ribbon_Rood ;               Button1.StateActive.BorderColor:= clBlack;               Button2.StateHover.Color := KleurPop + $00A0A000;               Button2.StateHover.BorderColor:= KleurPop;               Button2.StateActive.Color := Ribbon_Rood ;               Button2.StateActive.BorderColor:= clBlack;end;     // FormActivate  procedure TForm_Melding.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  Form_Melding.FormStyle := fsNormal;  CloseAction := caHide;end;     // FormClose  procedure TForm_Melding.FormCreate(Sender: TObject);begin  MessageButtonPressed := -1;  Button1.Visible := False;  Button2.Visible := False;  Color := Achter;end;    // FormCreate  procedure TForm_Melding.FormKeyDown(Sender: TObject; var Key: Word);begin  if Custom = False then begin    case MB of      bOK       : begin                  if Key = VK_O then begin                      Button1.Click;                      Key := 0;                    end;                  end;  // OK      bYesNo    : begin                    if Key = VK_Y then begin                      Button1.Click;                    Key := 0;                    end;                    if Key = VK_N then begin                      Button2.Click;                    Key := 0;                    end;                  end; // YesNo    bOKCancel : begin                    if Key = VK_O then begin                    Button1.Click;                      Key := 0;                  end;                    if Key = VK_C then begin                    Button2.Click;                      Key := 0;                  end;                  end; // OKCancel    end;     // MsgB  end;  // ifend;     // FormKeyDown  procedure TForm_Melding.FormShow(Sender: TObject);begin  Form_Melding.FormStyle := fsSystemStayOnTop;end;     // FormShow  procedure TForm_Melding.Melding(const MsgT: TMsgType; const MsgB: TMsgButton;                                const MsgStr, MsgCaption: string);begin  Form_Melding.Height := 195;  MessageButtonPressed := -1;  Custom := False;  MB := MsgB;  Form_Melding.Caption := MsgCaption;  Label_Message.Caption := MsgStr;  case MsgT of    mGeen     : begin                  //Ook lblMessage verschuiven                  Label_Message.Left := 10;                Label_Message.Top := 10;                  Label_Message.Width := 400;                  Show_JuistePop (mGeen);                end;     // mNone    mStop     : Show_JuistePop (mStop);    mInfo     : Show_JuistePop (mInfo);    mVraag1   : Show_JuistePop (mVraag1);    mVraag2   : Show_JuistePop (mVraag2);    mUitroep1 : Show_JuistePop (mUitroep1);    mUitroep2 : Show_JuistePop (mUitroep2);    mBuis     : Show_JuistePop (mBuis);    mGo       : Show_JuistePop (mGo);    mThink    : Show_JuistePop (mThink);    mSign     : Show_JuistePop (mSign);  mPotlood1 : Show_JuistePop (mPotlood1);    mPotlood2 : Show_JuistePop (mPotlood2);    mPDF      : Show_JuistePop (mPDF);    mKrant    : Show_JuistePop (mKrant);  end;     // MsgT  case MsgB of    bOK       : begin                  Button1.Left := 175;                  Button1.Top := 145;                  Button1.Caption := '  OK';                Button1.Visible := True;                  Form_Lint.ImageList_Buttons_16.GetBitmap(0, Button1.Glyph);                Button2.Visible := False;                end;  // OK    bYesNo  : begin                  Button1.Left := 95;                  Button1.Top := 145;                  Button1.Caption := 'Yes';                Button2.Caption := 'No';                  Form_Lint.ImageList_Buttons_16.GetBitmap(0, Button1.Glyph);                Form_Lint.ImageList_Buttons_16.GetBitmap(5, Button2.Glyph);                Button1.Visible := True;                  Button2.Visible := True;                end; // YesNo    bOKCancel : begin                Button1.Left := 95;                  Button1.Top := 145;                Button1.Caption := 'Ok';                  Button2.Caption := 'Cancel';                  Form_Lint.ImageList_Buttons_16.GetBitmap(1, Button1.Glyph);                  Form_Lint.ImageList_Buttons_16.GetBitmap(4, Button2.Glyph);                Button1.Visible := True;                  Button2.Visible := True;                end; // OKCancel  end;     // MsgB  ShowModal;end;    // Melding  procedure TForm_Melding.Melding_Alleen(const MsgT: TMsgType; const MsgStr, MsgCaption: string);begin  Button1.Visible := False;  Button2.Visible := False;  Form_Melding.Caption := MsgCaption;  Label_Message.Caption := MsgStr;  case MsgT of    mGeen     : begin                  //Ook lblMessage verschuiven                  Label_Message.Left := 10;                Label_Message.Top := 10;                  Label_Message.Width := 400;                  Show_JuistePop (mGeen);              end;     // mNone    mStop     : Show_JuistePop (mStop);    mInfo     : Show_JuistePop (mInfo);    mVraag1   : Show_JuistePop (mVraag1);    mVraag2   : Show_JuistePop (mVraag2);    mUitroep1 : Show_JuistePop (mUitroep1);    mUitroep2 : Show_JuistePop (mUitroep2);    mBuis     : Show_JuistePop (mBuis);    mGo       : Show_JuistePop (mGo);    mThink    : Show_JuistePop (mThink);    mSign     : Show_JuistePop (mSign);    mPotlood1 : Show_JuistePop (mPotlood1);    mPotlood2 : Show_JuistePop (mPotlood2);    mPDF      : Show_JuistePop (mPDF);    mKrant    : Show_JuistePop (mKrant);  end;   // MsgT  Form_Melding.Height := 145;  Form_Melding.FormStyle:=fsStayOnTop;  Show;end;     // Melding_Alleen  procedure TForm_Melding.Melding_Aangepast(const MsgT: TMsgType;                                          const MsgStr, MsgCaption: string;                                          const Btn1Msg, Btn2Msg: string;                                          const Btn1Gnr, Btn2Gnr: integer);begin  Form_Melding.Height := 195;  MessageButtonPressed := -1;  Custom := True;  Form_Melding.Caption := MsgCaption;  Label_Message.Caption := MsgStr;  case MsgT of    mGeen   : begin                  //Ook lblMessage verschuiven                Label_Message.Left := 10;                  Label_Message.Top := 10;                  Label_Message.Width := 400;                  Show_JuistePop (mGeen);                end;     // mNone    mStop     : Show_JuistePop (mStop);    mInfo     : Show_JuistePop (mInfo);    mVraag1   : Show_JuistePop (mVraag1);    mVraag2   : Show_JuistePop (mVraag2);    mUitroep1 : Show_JuistePop (mUitroep1);    mUitroep2 : Show_JuistePop (mUitroep2);    mBuis     : Show_JuistePop (mBuis);    mGo       : Show_JuistePop (mGo);    mThink    : Show_JuistePop (mThink);    mSign     : Show_JuistePop (mSign);    mPotlood1 : Show_JuistePop (mPotlood1);    mPotlood2 : Show_JuistePop (mPotlood2);    mPDF      : Show_JuistePop (mPDF);    mKrant    : Show_JuistePop (mKrant);  end;     // MsgT  Button1.Left := 95;  Button1.Top := 145;  Button1.Caption := ' ' + Btn1Msg;  Button2.Caption := ' ' + Btn2Msg;  if Btn1Gnr = -1 then      Button1.Glyph.Clear  else    Form_Lint.ImageList_Buttons_16.GetBitmap(Btn1Gnr, Button1.Glyph);  if Btn2Gnr = -1 then      Button1.Glyph.Clear  else    Form_Lint.ImageList_Buttons_16.GetBitmap(Btn2Gnr, Button2.Glyph);  Button1.Visible := True;  Button2.Visible := True;  ShowModal;end;    // Melding_Aangepast  procedure TForm_Melding.Show_JuistePop(const MsgT: TMsgType);begin               case MsgT of                 mGeen     : Image_Pop.Picture.Bitmap.Assign(nil);                 mInfo     : Form_Lint.ImageList_Rood.GetBitmap(01,Image_Pop.Picture.Bitmap);               mUitroep1 : Form_Lint.ImageList_Rood.GetBitmap(00,Image_Pop.Picture.Bitmap);               mUitroep2 : Form_Lint.ImageList_Rood.GetBitmap(14,Image_Pop.Picture.Bitmap);               mStop     : Form_Lint.ImageList_Rood.GetBitmap(05,Image_Pop.Picture.Bitmap);               mVraag1   : Form_Lint.ImageList_Rood.GetBitmap(03,Image_Pop.Picture.Bitmap);               mVraag2   : Form_Lint.ImageList_Rood.GetBitmap(13,Image_Pop.Picture.Bitmap);               mBuis     : Form_Lint.ImageList_Rood.GetBitmap(02,Image_Pop.Picture.Bitmap);               mGo       : Form_Lint.ImageList_Rood.GetBitmap(04,Image_Pop.Picture.Bitmap);               mThink    : Form_Lint.ImageList_Rood.GetBitmap(06,Image_Pop.Picture.Bitmap);               mSign     : Form_Lint.ImageList_Rood.GetBitmap(12,Image_Pop.Picture.Bitmap);               mPotlood1 : Form_Lint.ImageList_Rood.GetBitmap(08,Image_Pop.Picture.Bitmap);               mPotlood2 : Form_Lint.ImageList_Rood.GetBitmap(17,Image_Pop.Picture.Bitmap);               mPDF      : Form_Lint.ImageList_Rood.GetBitmap(18,Image_Pop.Picture.Bitmap);               mKrant    : Form_Lint.ImageList_Rood.GetBitmap(11,Image_Pop.Picture.Bitmap);             end;  // MsgTend;     // Show_JuistePop  end. ---------------------------------------------------------------------- Rik · 2025-02-05 08:11 QuotePosted by: ASerge It must be rendered in the OnPaint event for a form created via CreateMessageDialog.Indeed, I should have thought of that. After adding an OnPaint event it works fine, thanks. QuotePosted by: madref why not create a separate form for all your messagesNo doubt that this would also do the job. But using CreateMessageDialog it takes far less lines of code, about 25 lines instead of over 300 lines. ---------------------------------------------------------------------- d2010 · 2025-02-05 09:35 You can add many items/ inside PageControl. You search "PageControl" Code: [Select]    object PageControl: TPageControl       Left = 12       Top = 12       Width = 409       Height = 227       HelpContext = 1650       ActivePage = PakListSheet       Align = alClient       MultiLine = True       TabOrder = 0       object AutoexecPage: TTabSheet         HelpContext = 1770         Caption = 'Autoexec.bat'         object TLabel           Left = 648           Top = 0           Width = 44           Height = 13           Caption = 'Location:'         end         object Memo2: TMemo           Left = 0           Top = 0           Width = 401           Height = 199           Align = alClient           Font.Charset = DEFAULT_CHARSET           Font.Color = clWindowText           Font.Height = -15           Font.Name = 'MS Sans Serif'           Font.Style = []           ParentFont = False           ScrollBars = ssBoth           TabOrder = 0         end       end       object DirCondPage: TTabSheet Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMainForm.Exit_zerop1Click(Sender: TObject);Var amsg_exit:TCloseAction;    Gcw_Cancelled:boolean;begin EroareMsgOkai := true;      Gcw_Cancelled:=false;      Label4que.caption:='qQuit?';      Case (Exit_zerop.checked) offals:  Begin            dfn_dcl_yesno4.tab:=PageControl.ActivePage;            PageControl.ActivePage:=PakListSheet;Refresh;            dfn_dcl_yesno4.cmd:=epYesQuit;            Exit_zerop.checked:=not Exit_zerop.checked;       End;true:  Begin if (PageControl.ActivePage<>dfn_dcl_yesno4.tab) then                   PageControl.ActivePage:=dfn_dcl_yesno4.tab;             Refresh;           Exit_zerop.checked:=not Exit_zerop.checked;      End;     End;     Refresh;end;