博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
再学 GDI+[12]: 准备工作 - 矩形命中
阅读量:7065 次
发布时间:2019-06-28

本文共 2223 字,大约阅读时间需要 7 分钟。

  hot3.png

本例效果图:
26153809_cIHp.gif

代码文件:

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs;type  TForm1 = class(TForm)    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure FormPaint(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}uses GDIPOBJ, GDIPAPI;var  f: Boolean;  x1,y1,x2,y2: Integer;  RectArr: array of TRect;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  f := True;  x1 := X;  y1 := Y;  x2 := X;  y2 := Y;end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);var  i: Integer;begin  if f then  begin    Canvas.DrawFocusRect(Rect(x1,y1,x2,y2));    x2 := X;    y2 := Y;    Canvas.DrawFocusRect(Rect(x1,y1,x2,y2));  end else begin    Text := '';    for i := Low(RectArr) to High(RectArr) do      if PtInRect(RectArr[i], Point(X,Y)) then        Text := Format('在第 %d 个矩形中', [i+1]);  end;end;procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if not f then Exit;  SetLength(RectArr, Length(RectArr)+1);  RectArr[High(RectArr)] := Rect(x1,y1,x2,y2);  f := False;  Repaint;end;procedure TForm1.FormPaint(Sender: TObject);var  g: TGPGraphics;  p: TGPPen;  i: Integer;begin  g := TGPGraphics.Create(Canvas.Handle);  p := TGPPen.Create(aclRed, 1);  g.Clear(aclWhite);  for i := Low(RectArr) to High(RectArr) do    g.DrawRectangle(p, MakeRect(RectArr[i]));  g.Free;  p.Free;end;end.
窗体文件:

object Form1: TForm1  Left = 0  Top = 0  Caption = 'Form1'  ClientHeight = 179  ClientWidth = 277  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  Position = poDesktopCenter  OnMouseDown = FormMouseDown  OnMouseMove = FormMouseMove  OnMouseUp = FormMouseUp  OnPaint = FormPaint  PixelsPerInch = 96  TextHeight = 13end

转载于:https://my.oschina.net/hermer/blog/320587

你可能感兴趣的文章
ttlsa教程系列之mongodb——(五)mongodb架构-复制原理&复制集
查看>>
虚拟主机通过修改.htaccess将入口重定向到public文件夹
查看>>
nginx快速安装
查看>>
Kinect for windows的脸部识别
查看>>
MySQL 运维笔记(一)—— 终止高负载SQL
查看>>
Carrie Higbie:数据中心的绿色布线之道
查看>>
ECS之初体验
查看>>
我的友情链接
查看>>
【风云原创】Flash技术将被Html5枪毙,Silverlight将何去何从?
查看>>
power shell测试wmi
查看>>
话里话外:成功CEO的用人之道——按需激励
查看>>
openwrt无线连接互联网的实现原理【1】
查看>>
WPS for Linux(ubuntu)字体配置(字体缺失解决办法)
查看>>
谷歌为Pwnium***竞赛再掷重金 将提供200万美元奖金
查看>>
搭建K8S高可用集群(二进制方式)
查看>>
BSON与JSON的区别
查看>>
我的友情链接
查看>>
Play Framework 模板里使用注入访问数据层
查看>>
Win2008学习(十一),解决Remote App Web访问的证书问题
查看>>
python 实现 自动oa 签到签退 发送邮件提醒
查看>>