DELPHI Point(X, Y)
时间: 2023-12-14 14:04:19 浏览: 23
Point(X, Y) in Delphi is a function that returns a TPoint record type with the coordinates specified by the parameters X and Y.
The TPoint record type contains two fields: X and Y, both of type Integer. This record type is used to represent a point in a two-dimensional Cartesian coordinate system.
Example Usage:
var
MyPoint: TPoint;
begin
MyPoint := Point(10, 20);
// MyPoint.X = 10, MyPoint.Y = 20
end;
相关问题
delphi绘制爱心代码
以下是 Delphi 中绘制爱心的示例代码:
```delphi
procedure TForm1.DrawHeart(X, Y: Integer; Size: Integer);
var
Points: array[0..6] of TPoint;
Heart: HRGN;
begin
Points[0] := Point(X, Y + Size div 4);
Points[1] := Point(X - Size div 4, Y);
Points[2] := Point(X - Size div 2, Y + Size div 4);
Points[3] := Point(X, Y + Size div 2);
Points[4] := Point(X + Size div 2, Y + Size div 4);
Points[5] := Point(X + Size div 4, Y);
Points[6] := Point(X, Y + Size div 4);
Heart := CreatePolygonRgn(Points, Length(Points), WINDING);
Canvas.Brush.Color := clRed;
FillRgn(Canvas.Handle, Heart, Canvas.Brush.Handle);
DeleteObject(Heart);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DrawHeart(100, 100, 100);
end;
```
以上代码会在画布上绘制一个大小为 100 的红色爱心,位置在 (100, 100) 处。你可以根据自己的需要更改位置和大小。
delphi 鼠标拖拽panel
在 Delphi 中实现鼠标拖拽 Panel 的方法如下:
1. 在鼠标按下事件中获取鼠标位置和 Panel 的位置
```
procedure TForm1.PanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := True;
FMousePos := Point(X, Y);
FPanelPos := Panel1.Left;
end;
```
2. 在鼠标移动事件中更新 Panel 的位置
```
procedure TForm1.PanelMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FDragging then
Panel1.Left := FPanelPos + (X - FMousePos.X);
end;
```
3. 在鼠标释放事件中停止拖拽
```
procedure TForm1.PanelMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
end;
```
完整代码如下:
```
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
procedure PanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PanelMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure PanelMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
FDragging: Boolean;
FMousePos: TPoint;
FPanelPos: Integer;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.PanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := True;
FMousePos := Point(X, Y);
FPanelPos := Panel1.Left;
end;
procedure TForm1.PanelMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FDragging then
Panel1.Left := FPanelPos + (X - FMousePos.X);
end;
procedure TForm1.PanelMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
end;
end.
```