урок на делфи 25 - Паинт для рисования
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ButtonGroup,
Vcl.ExtCtrls, Vcl.Buttons, System.Bluetooth, System.Bluetooth.Components,
Vcl.ColorGrd, Vcl.Samples.Spin, Vcl.ExtDlgs;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
ColorBox1: TColorBox;
SpinEdit1: TSpinEdit;
SavePictureDialog1: TSavePictureDialog;
Button1: TButton;
OpenPictureDialog1: TOpenPictureDialog;
Button3: TButton;
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure ColorBox1Change(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var Bitmap:TBitmap;
begin
Bitmap:=TBitmap.create;
SavePictureDialog1.Title:='сохранить файл';
if SavePictureDialog1.Execute then
begin
Bitmap.Width := PaintBox1.Width;
Bitmap.Height := PaintBox1.Height;
BitBlt(Bitmap.Canvas.Handle,0,0,Bitmap.Width,Bitmap.Height,PaintBox1.Canvas.Handle,0,0,SRCCOPY);
Bitmap.SaveToFile(SavePictureDialog1.FileName+'.bmp');
end;
FreeAndNil(Bitmap);
end;
procedure TForm1.Button3Click(Sender: TObject);
var bmp:TBitmap;
begin
OpenPictureDialog1.Title := 'открыть файл...';
if (OpenPictureDialog1.Execute) then
begin
bmp:=TBitmap.create;
bmp.loadfromfile(OpenPictureDialog1.FileName);
paintbox1.width:=bmp.width;
paintbox1.height:=bmp.height;
paintbox1.canvas.draw(0,0,bmp);
bmp.Free;
end;
end;
procedure TForm1.ColorBox1Change(Sender: TObject);
begin
PaintBox1.Canvas.Create.Pen.Color:=ColorBox1.Selected;
PaintBox1.Canvas.Pen.Width:=SpinEdit1.Value;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PaintBox1.Canvas.Create.Pen.Color:=ColorBox1.Selected;
PaintBox1.Canvas.Pen.Width:=SpinEdit1.Value;
end;
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
PaintBox1.Canvas.MoveTo(x,y);
if Button=mbLeft then
begin
PaintBox1.Tag:=1;
end;
end;
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if PaintBox1.Tag=1 then
PaintBox1.Canvas.LineTo(x,y);
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (PaintBox1.Tag=1) and (Button=mbLeft) then
PaintBox1.Tag:=0;
end;
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
PaintBox1.Canvas.Pen.Width:=SpinEdit1.Value;
end;
end.