• 用 GDI 操作 EMF 文件[4]: 重绘 EMF


    本例效果图:



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        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 Button1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    var
      HMetaFile: HENHMETAFILE;
      f: Boolean;
      x1,y1: Integer;
      R: TRect;
    
    procedure TForm1.FormCreate(Sender: TObject);
    const
      Path = 'C:\Temp\MyMetaFile.emf';
    begin
      HMetaFile := GetEnhMetaFile(PChar(Path));
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      DeleteEnhMetaFile(HMetaFile);
    end;
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      f := True;
      x1 := X;
      y1 := Y;
      R := Rect(x1,y1,X,Y);
    end;
    
    procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if not f then Exit;
      DrawFocusRect(Canvas.Handle, R);
      R := Rect(x1,y1,X,Y);
      DrawFocusRect(Canvas.Handle, R);
      R := Rect(x1,y1,X,Y);
    end;
    
    procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      f := False;
      PlayEnhMetaFile(Canvas.Handle, HMetaFile, R);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Refresh;
    end;
    
    end.
    
    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 206
      ClientWidth = 339
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      Position = poDesktopCenter
      OnCreate = FormCreate
      OnDestroy = FormDestroy
      OnMouseDown = FormMouseDown
      OnMouseMove = FormMouseMove
      OnMouseUp = FormMouseUp
      PixelsPerInch = 96
      TextHeight = 13
      object Button1: TButton
        Left = 256
        Top = 173
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 0
        OnClick = Button1Click
      end
    end
    
  • 相关阅读:
    c# 对文件操作
    c# 获取当前绝对路径
    c# 过滤特殊字符
    c# txt代码转换成HTML格式
    c# 对象集合转Json
    c# DataReader转换为Json
    c# DataSet转换为Json
    ABAP-SAP的LUW和DB的LUW的区别
    ABAP-关于隐式与显式的DB Commit
    ABAP-Keyword Documentation
  • 原文地址:https://www.cnblogs.com/del/p/1213770.html
Copyright © 2020-2023  润新知