How is made event management? lazarus / 31-LCL ---------------------------------------------------------------------- Borneq · 2017-08-10 21:45 How is WinApi wrapped? With each window HWND is associated window procedure (callback)? This procedure can handle WM_PAINT messages; between BeginPaint- EndPaint controls can draw self. But how user application have access to Canvas from any event? OnCreate, OnClick, OnMouseMove etc. How they can draw on Canvas? ---------------------------------------------------------------------- RAW · 2017-08-11 03:46 Don't know if I understand this...  OnPaint Repaint ---------------------------------------------------------------------- Borneq · 2017-08-11 05:28 Is page: http://wiki.lazarus.freepascal.org/LCL_Internals but nothing about Paint ---------------------------------------------------------------------- RAW · 2017-08-11 06:35 I thought you just want to paint something like this...  No harm meant... 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 TForm1.FormCreate(Sender: TObject); Begin  DoubleBuffered:= True; // Classic Theme  Height        := 400;  Width         := 500;  Position    := poDesktopCenter; End;  Procedure TForm1.FormPaint(Sender: TObject); Begin  If booColor  Then   Begin    Canvas.Brush.Color:= clBlue;    Canvas.Brush.Style:= bsSolid;    Canvas.Ellipse(0, 0, 150, 300);   End  Else   Begin    Canvas.Brush.Color:= clYellow;    Canvas.Brush.Style:= bsSolid;    Canvas.Ellipse(0, 0, 150, 300);   End; End;  Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;                               Shift : TShiftState; X, Y: Integer); Begin  If Button = mbRight  Then   Begin    booColor:= True;    Repaint;   End;   If Button = mbLeft  Then   Begin    booColor:= False;    Repaint;   End; End; ---------------------------------------------------------------------- Borneq · 2017-08-11 07:41 Problem is not drawing on FormPaint but direct drawing: 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 TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;                                   Shift : TShiftState; X, Y: Integer);    Begin       Canvas.Brush.Color:= clBlue;       Canvas.Brush.Style:= bsSolid;       Canvas.Ellipse(0, 0, 150, 300);    End; ---------------------------------------------------------------------- RAW · 2017-08-11 08:15 Try 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 Unit1;{$MODE OBJFPC}{$H+}{$J-} Interface USES  Classes,  SysUtils, Forms,  Controls, Graphics, LCLType,  ExtCtrls;  TYPE  TForm1 = Class(TForm)    Procedure FormCreate  (Sender: TObject);   Procedure FormKeyDown (Sender: TObject; Var Key: Word; Shift: TShiftState);     PRIVATE     IMG: TImage;  End;  VAR  Form1: TForm1; Implementation{$R *.LFM}  Procedure TForm1.FormCreate(Sender: TObject); Begin  DoubleBuffered:= True;   IMG       := TImage.Create(Self);  IMG.Align := alClient;  IMG.Parent:= Self;  IMG.Show; End;  Procedure TForm1.FormKeyDown(Sender: TObject; Var Key: Word;                           Shift : TShiftState);  Var   BMP: TBitmap; Begin  If Key = VK_RETURN  Then   Begin    BMP:= TBitmap.Create;     Try      BMP.Height:= Self.ClientHeight;      BMP.Width := Self.ClientWidth Div 2;       BMP.Canvas.Brush.Color:= clRed;      BMP.Canvas.Brush.Style:= bsSolid;      BMP.Canvas.FillRect(BMP.Canvas.ClipRect);       IMG.Picture.Bitmap.Assign(BMP);     Finally      BMP.Free;     End;   End; End; END. Just kidding ... there is no other event for drawing...  Use >> OnPaint << ... ---------------------------------------------------------------------- RAW · 2017-08-11 08:39 If you don't like OnPaint then this is definitely for you ...  Try this.. OnClick-Drawing...  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 Unit1;{$MODE OBJFPC}{$H+}{$J-} Interface USES  Classes,  SysUtils, Forms,  Controls, Graphics, ExtCtrls,  StdCtrls;  TYPE  TForm1 = Class(TForm)    Procedure FormCreate (Sender: TObject);   Procedure FormResize (Sender: TObject);   Procedure FormClick  (Sender: TObject);   Procedure ShowVAT;     PRIVATE     PanVAT: TPanel;  End;  VAR  Form1: TForm1; Implementation{$R *.LFM}  Procedure TForm1.ShowVAT;  Var   LabLeft  : TLabel;   iFontSize: Integer;    IMG: TImage;   BMP: TBitmap; Begin  PanVAT               := TPanel.Create(Self);  PanVAT.BorderStyle   := bsSingle;  PanVAT.BevelOuter    := bvRaised;  PanVAT.Color         := clBlack;  PanVAT.BorderWidth   := 0;  PanVAT.Caption       := '';  PanVAT.DoubleBuffered:= True;  PanVAT.SetBounds     (Self.ClientWidth Div 2,                        0,                        Self.ClientWidth Div 2,                        Self.ClientHeight);  PanVAT.Parent        := Self;    LabLeft             := TLabel.Create(PanVAT);  LabLeft.Transparent := True;  LabLeft.AutoSize    := True;  LabLeft.Font.Color  := clLime;  LabLeft.Font.Name   := 'Lucida Console';  LabLeft.Font.Quality:= fqAntialiased;  LabLeft.Font.Size   := PanVAT.ClientWidth Div 30;  LabLeft.Font.Style  := [fsBold];  LabLeft.Align       := alLeft;  LabLeft.Alignment   := taRightJustify;  LabLeft.Caption     := 'Current Period' +sLineBreak+                         'Return Due'     +sLineBreak+                                         sLineBreak+                                         sLineBreak+                         'Period Shown'   +sLineBreak+                         'Output VAT'     +sLineBreak+                       'Input VAT'      +sLineBreak+                       'VAT Due'        +sLineBreak+                         'Sales'        +sLineBreak+                         'Purchases'      +sLineBreak+                         'Adjustment VAT' +sLineBreak+                       'Adjustment Goods';  LabLeft.Parent      := PanVAT;    iFontSize:= LabLeft.Font.Size;   BMP:= TBitmap.Create;   Try    BMP.Height            := iFontSize;    BMP.Width             := PanVAT.ClientWidth;    BMP.Canvas.Brush.Color:= clLime;    BMP.Canvas.Brush.Style:= bsSolid;    BMP.Canvas.FillRect      (BMP.Canvas.ClipRect);     IMG:= TImage.Create(PanVAT);    IMG.Picture.Assign(BMP);    IMG.SetBounds(0,                  Trunc(iFontSize*3.5),                  BMP.Width,                  BMP.Height);    IMG.Parent:= PanVAT;   Finally    BMP.Free;   End; End;  Procedure TForm1.FormClick(Sender: TObject); Begin  If Not Assigned(PanVAT)  Then ShowVAT  Else   Begin    PanVAT.Free;    PanVAT:= Nil;   End; End;  Procedure TForm1.FormResize(Sender: TObject); Begin  If Assigned(PanVAT)  Then   Begin    PanVAT.Free;    ShowVAT;   End; End;  Procedure TForm1.FormCreate(Sender: TObject); Begin  DoubleBuffered:= True;   Constraints.MinHeight:= 200;  Constraints.MinWidth := 300; End; END. ---------------------------------------------------------------------- RAW · 2017-08-12 11:44 QuoteProblem is not drawing on FormPaint but direct drawing: Obviously I'm not smart enough... This is what you want... isn't it ??? EDIT: If you really want to paint like MSPaint or GIMP, then you can use the TPaintbox or better BGRABitmap (semitransparent pixel) or FreePascal only or Graphics32 or VampyreImagingLIB or AGGPAS.... And probably better a fast timer and not OnMouseMove...  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 Unit1; {$MODE OBJFPC}{$H+}{$J-} Interface USES  Classes, SysUtils, Forms, Controls, Graphics;  TYPE  TForm1 = Class(TForm)    Procedure FormMouseUp   (Sender: TObject; Button: TMouseButton;                          Shift : TShiftState; X, Y: Integer);   Procedure FormMouseMove (Sender: TObject; Shift: TShiftState;                          X, Y: Integer);   Procedure FormMouseDown (Sender: TObject; Button: TMouseButton;                            Shift : TShiftState; X, Y: Integer);    PRIVATE     booDrawing: Boolean;  End;  VAR  Form1: TForm1; Implementation {$R *.LFM}  Procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState;                             X, Y: Integer); Begin  If booDrawing  Then   Begin  Canvas.Brush.Color:= clBlue;    Canvas.Rectangle  (X, Y-10, X+10, Y);   End; End;  Procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;                             Shift : TShiftState; X, Y: Integer); Begin  booDrawing:= False; End;  Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;                             Shift : TShiftState; X, Y: Integer); Begin  If Button = mbLeft  Then booDrawing:= True;   If Button = mbRight  Then Repaint; End; END. ---------------------------------------------------------------------- RAW · 2017-08-12 12:45 Paint on a form like MSPaint... almost... this is funny...  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 Unit1; {$MODE OBJFPC}{$H+}{$J-} Interface USES  Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls;  TYPE  TForm1 = Class(TForm)    Timer1: TTimer;    Procedure FormCreate    (Sender: TObject);   Procedure FormMouseDown (Sender: TObject; Button: TMouseButton;                          Shift : TShiftState; X, Y: Integer);   Procedure FormMouseUp   (Sender: TObject; Button: TMouseButton;                          Shift : TShiftState; X, Y: Integer);   Procedure Timer1Timer   (Sender: TObject);     PRIVATE     booPainting: Boolean;  End;  VAR  Form1: TForm1; Implementation {$R *.LFM}  Procedure TForm1.FormCreate(Sender: TObject); Begin  Canvas.Pen.Style:= psSolid;  Canvas.Pen.Color:= clBlue;  Canvas.Pen.Width:= 10; End;  Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;                               Shift : TShiftState; X, Y: Integer); Begin  If Button = mbLeft  Then booPainting:= True;   If Button = mbRight  Then Repaint; End;  Procedure TForm1.Timer1Timer(Sender: TObject);  Var   p: TPoint; Begin  If booPainting  Then   Begin    p:= ScreenToClient(Mouse.CursorPos);    Canvas.LineTo(p.x, p.y);   End; End;  Procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;                           Shift : TShiftState; X, Y: Integer); Begin  booPainting:= False; End; END.