📄 invalidaterectunit.pas
字号:
unit InvalidateRectUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
Image1: TImage;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
var
InvalidRectangle: TRect; //rectangle to invalidate
begin
{define the rectangle}
InvalidRectangle := Rect(10, 10, 110, 110);
{erase only the rectangular area}
InvalidateRect(Form1.Handle, @InvalidRectangle, TRUE);
end;
procedure TForm1.WMPaint(var Msg: TWMPaint);
var
InvalidRect: TRect; // holds the invalid rectangular area
PaintStruct: TPaintStruct; // holds painting information
begin
{retrieve the invalid rectangle}
GetUpdateRect(Handle, InvalidRect, TRUE);
{begin the painting process. this validates the invalid region}
BeginPaint(Handle, PaintStruct);
{if the entire client area is invalid...}
if EqualRect(InvalidRect, ClientRect) then
{...redraw the bitmap in Image1 to the canvas}
Canvas.Draw(0, 0, Image1.Picture.Bitmap)
else
begin
{...otherwise, draw a red rectangle in the entire invalid rectangular
area, and label it as a previously invalid area}
Canvas.Brush.Color := clRed;
Canvas.Rectangle(InvalidRect.Left, InvalidRect.Top, InvalidRect.Right,
InvalidRect.Bottom);
Canvas.TextOut(InvalidRect.Left+10, InvalidRect.Top+10, 'Invalid Rect');
end;
{end the painting operation}
EndPaint(Handle, PaintStruct);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -