target.pas

来自「Drag files and Drop to delphi forms 0402」· PAS 代码 · 共 66 行

PAS
66
字号
unit Target;

interface

uses
  DragDrop,
  DropTarget,
  DragDropFormats,
  DragDropText,
  DragDropTimeOfDay,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TFormTarget = class(TForm)
    Panel2: TPanel;
    PanelDest: TPanel;
    DropTextTarget1: TDropTextTarget;
    Panel5: TPanel;
    procedure DropTextTarget1Drop(Sender: TObject; ShiftState: TShiftState;
      Point: TPoint; var Effect: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    TimeOfDayDataFormat: TTimeOfDayDataFormat;
  public
    { Public declarations }
  end;

var
  FormTarget: TFormTarget;

implementation

{$R *.DFM}

procedure TFormTarget.FormCreate(Sender: TObject);
begin
  // Add our custom data and clipboard format to the drag/drop component.
  // This needs to be done for both the drop source and target.
  TimeOfDayDataFormat := TTimeOfDayDataFormat.Create(DropTextTarget1);
end;

procedure TFormTarget.DropTextTarget1Drop(Sender: TObject;
  ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
var
  Time: TDateTime;
begin
  // Determine if we got our custom format.
  if (TimeOfDayDataFormat.HasData) then
  begin
    // Convert the time-of-day info to a TDateTime so we can display it.
    Time := EncodeTime(TimeOfDayDataFormat.TOD.hours,
      TimeOfDayDataFormat.TOD.minutes, TimeOfDayDataFormat.TOD.seconds,
      TimeOfDayDataFormat.TOD.milliseconds);

    // Display the data.
    PanelDest.Caption := FormatDateTime('hh:nn:ss.zzz', Time);
    PanelDest.Color := TimeOfDayDataFormat.TOD.color;
    PanelDest.Font.Color := not(PanelDest.Color) and $FFFFFF;
  end else
    PanelDest.Caption := TDropTextTarget(Sender).Text;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?