Delphi的绘图功能[12]

//奇妙的异或运算, 就这些简单的代码, 反复点击按钮...procedure TForm1.Button1Click(Sender: TObject);
begin
 Canvas.Pen.Color := clYellow; {指定笔颜色为黄色}
 Canvas.Pen.Width := 20;    {笔宽 20}
 Canvas.Pen.Mode := pmXor;   {指定画笔模式为: 画笔色与背景色的异或运算}
 {画线}
 Canvas.MoveTo(0,0);
 Canvas.LineTo(ClientWidth,ClientHeight);
end;

//效果图:

//做一个橡皮线的示例:unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;
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);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
var
 x1,y1,x2,y2: Integer; {直线两个端点的坐标}
 f: Boolean;      {判断鼠标是否点下}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
begin
 x1 := X; y1 := Y;
 x2 := X; y2 := Y;
 Canvas.Pen.Color := clRed;
 Canvas.Pen.Width := 2;
 Canvas.Pen.Mode := pmXor;
 f := True;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
 Y: Integer);
begin
 if f then
 begin

时间: 2024-12-24 20:20:40

Delphi的绘图功能[12]的相关文章

Delphi的绘图功能[9]

//第一种重载的声明:TextRect( Rect: TRect; {矩形} X, Y: Integer; {相对于窗体的位置} const Text: string {文本});{如果要输出的文本超出指定的矩形将 不被显示}------------------------------------------------------------------------------ --//第一种重载的举例:procedure TForm1.Button1Click(Sender: TObject

Delphi的绘图功能[2]

绘图需要有纸.画笔.画刷; Delphi 有 Canvas.Pen.Brush. Canvas 就是画布, 譬如窗体的 Canvas 属性, 就是窗体的画布; Pen 是画笔, 可以设置笔色.笔宽等等; Brush 是画刷, 可以设置颜色等等. //举例:{绘制直线} procedure TForm1.Button1Click(Sender: TObject); begin Canvas.Pen.Color := clRed; {设置画笔颜色} Canvas.Pen.Width := 2; {设

Delphi的绘图功能[15]

procedure TForm1.Button1Click(Sender: TObject); var str: string; wh: TSize; w,h: Integer; begin {前面用过 Canvas.TextWidth.Canvas.TextHeight} str := '万'; w := Canvas.TextWidth(str); h := Canvas.TextHeight(str); ShowMessage(Format('宽度: %d; 高度: %d', [w,h])

Delphi的绘图功能[14]

Delphi 的 Graphic 单元有五个重要的图像类: TGraphic.TBitmap.TMetafile.TIcon.TPicture. TBitmap 用来操作位图; TMetafile 用来操作图元文件; TIcon 用来操作图标(包括鼠标指针)文件; TBitmap.TMetafile.TIcon 都是 TGraphic 的子类, 由于 TCanvas.Draw(X, Y: Integer; Graphic: TGraphic); 的第三个参数就是 TGraphic 类型, 所以它

Delphi的绘图功能[13]

//画刷类 TBrush 有三个重要属性: Color.Style.Bitmap. {Style: 样式; Delphi 为画刷定义了样式枚举 TBrushStyle, 包含以下样式:}bsSolid bsClear bsHorizontal bsVertical bsFDiagonal bsBDiagonal bsCross bsDiagCross //下面小程序展示了上面的其中填充样式:var i,n: Integer; r: TRect; begin Canvas.Pen.Color :=

Delphi的绘图功能[11]

//TPen 的主要属性有四: Color.Width.Style.Mode {Color: 颜色}{Width: 宽度; 默认是 1; 如果 赋予 <= 0 的值, 会使用默认值} {Style: 样式; Delphi 定义了笔样式枚举 TPenStyle, 包含以下样式:} psSolid = 0; {实线} psDash = 1; {段线; 要求笔宽<=1} psDot = 2; {点线; 要求笔宽<=1} psDashDot = 3; {线.点; 要求笔宽<=1} psDa

Delphi的绘图功能[10]

//先来个例子:procedure TForm1.FormPaint(Sender: TObject); const S = '万一的 Delphi 博客'; var font: TFont; begin font := TFont.Create; font.Name := '微软雅黑'; font.Style := [fsBold, fsItalic]; font.Color := clRed; font.Height := 72; Canvas.Font := font; Canvas.Te

Delphi的绘图功能[8]

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R

Delphi的绘图功能[7]

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Se