source: DpiControls/Demo/UDpiFormMain.pas

Last change on this file was 585, checked in by chronos, 2 months ago
File size: 3.3 KB
Line 
1unit UDpiFormMain;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, Dpi.Controls, Dpi.ExtCtrls, Dialogs, Dpi.Graphics, Dpi.Forms,
9 Types;
10
11type
12
13 { TDpiFormMain }
14
15 TDpiFormMain = class(TForm)
16 DpiPaintBox1: TPaintBox;
17 procedure DpiButton1Click(Sender: TObject);
18 procedure DpiFormMainCreate(Sender: TObject);
19 procedure DpiFormMainDestroy(Sender: TObject);
20 procedure DpiPaintBox1Paint(Sender: TObject);
21 private
22 Button: TButton;
23 ButtonClose: TButton;
24 Image: TImage;
25 ListBox: TListBox;
26 PaintBox: TPaintBox;
27 Bitmap: TBitmap;
28 procedure ButtonCloseClick(Sender: TObject);
29 public
30 end;
31
32var
33 DpiFormMain: TDpiFormMain;
34
35implementation
36
37{$R *.lfm}
38
39{ TDpiFormMain }
40
41procedure TDpiFormMain.DpiFormMainCreate(Sender: TObject);
42var
43 I: Integer;
44 X, Y: Integer;
45begin
46 Button := TDpiButton.Create(DpiFormMain);
47 Button.Parent := Self;
48 Button.SetBounds(10, 10, 100, 30);
49 Button.Caption := 'Click me';
50 Button.Visible := True;
51 Button.OnClick := @DpiButton1Click;
52
53 ButtonClose := TDpiButton.Create(DpiFormMain);
54 ButtonClose.Parent := Self;
55 ButtonClose.SetBounds(120, 10, 100, 30);
56 ButtonClose.Caption := 'Close';
57 ButtonClose.Visible := True;
58 ButtonClose.OnClick := @ButtonCloseClick;
59
60 Image := TDpiImage.Create(DpiFormMain);
61 Image.Parent := Self;
62 Image.SetBounds(150, 10, 100, 100);
63 Image.Visible := True;
64 Image.Stretch := True;
65 Image.VclImage.Picture.LoadFromFile('dance.jpg');
66 //Image.Picture.LoadFromFile('dance.jpg');
67
68 ListBox := TDpiListBox.Create(DpiFormMain);
69 for I := 0 to 10 do
70 ListBox.VclListBox.Items.Add('Item ' + IntToStr(I));
71 ListBox.Parent := Self;
72 ListBox.SetBounds(250, 10, 100, 100);
73 ListBox.Visible := True;
74
75 PaintBox := TDpiPaintBox.Create(DpiFormMain);
76 PaintBox.Parent := Self;
77 PaintBox.BoundsRect := Bounds(0, 100, 200, 200);
78 PaintBox.OnPaint := @DpiPaintBox1Paint;
79 PaintBox.Visible := True;
80
81 Bitmap := TDpiBitmap.Create;
82 Bitmap.PixelFormat := pf24bit;
83 Bitmap.SetSize(120, 50);
84 for Y := 0 to Bitmap.Height - 1 do
85 for X := 0 to Bitmap.Width - 1 do
86 Bitmap.Canvas.Pixels[X, Y] := X mod 255;
87 Bitmap.LoadFromFile('dance.bmp');
88end;
89
90procedure TDpiFormMain.DpiFormMainDestroy(Sender: TObject);
91begin
92 FreeAndNil(Button);
93 FreeAndNil(Image);
94 FreeAndNil(ListBox);
95end;
96
97procedure TDpiFormMain.DpiPaintBox1Paint(Sender: TObject);
98var
99 X, Y: Integer;
100begin
101 with PaintBox.Canvas do begin
102 Brush.Color := clWhite;
103 Brush.Style := bsSolid;
104 FillRect(Bounds(0, 0, PaintBox.Width, PaintBox.Height));
105 Caption := IntToStr(Width);
106 Pen.Color := clGreen;
107 Pen.Style := psSolid;
108 MoveTo(0, 0);
109 LineTo(100, 100);
110 Font.Color := clRed;
111 Font.Size := 20;
112 TextOut(10, 10, 'Scaled text');
113
114 Brush.Color := clBlue;
115 Rectangle(Bounds(20, 30, 60, 30));
116
117 Bitmap.Dpi := DpiScreen.Dpi;
118 DpiBitBltCanvas(PaintBox.Canvas, 0, 0, Bitmap.Width, Bitmap.Height, Bitmap.Canvas, 0, 0);
119 end;
120end;
121
122procedure TDpiFormMain.ButtonCloseClick(Sender: TObject);
123begin
124 ModalResult := mrOk;
125end;
126
127procedure TDpiFormMain.DpiButton1Click(Sender: TObject);
128var
129 DpiForm: TDpiForm;
130begin
131 //ShowMessage('Hello');
132 DpiForm := TDpiFormMain.CreateNew(Self);
133 DpiForm.Name := 'Form10';
134 DpiForm.Caption := 'Modal form';
135 DpiForm.SetBounds(200, 150, 400, 200);
136 DpiForm.ShowModal;
137end;
138
139end.
140
Note: See TracBrowser for help on using the repository browser.