Starting to use GDI+ in Delphi. Need to draw a couple smooth straight lines. For example trying to draw diagonal line on the form (from left top corner to right bottom) but nothing appear. What's wrong with that code (Delphi XE3, Windows 10 x64)?
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Winapi.GDIPAPI, Winapi.GDIPOBJ;
type
TForm2 = class(TForm)
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormPaint(Sender: TObject);
var
graphics: TGPGraphics;
gpPen: TGPPen;
begin
graphics := TGPGraphics.Create(Self.Canvas.Handle);
try
graphics.SetSmoothingMode(SmoothingModeAntiAlias8x8);
gpPen := TGPPen.Create(clBlue, 3);
try
graphics.DrawLine(gpPen, 0, 0, ClientWidth, ClientHeight);
finally
gpPen.Free;
end;
finally
graphics.Free;
end;
end;
procedure TForm2.FormResize(Sender: TObject);
begin
Repaint;
end;
end.
