zoukankan      html  css  js  c++  java
  • Delphi 拖拽的用法

    1.如果把DragMode设置成dmAutoMatic 自动就会有拖拽效果。

    2.如果把DragMode设置成dmManual,则需要调用BeginDrag才起作用,这个函数有两个参数(Immediate: Boolean; Threshold: Integer)

      Immediate = true 则拖拽操作会立刻开始,鼠标变成dragCursor类型,Immediate = false 当达到Threshold设定的值时,会产生拖拽操作。

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Label1: TLabel;
        ListBox1: TListBox;
        procedure Button1Click(Sender: TObject);
        procedure Edit1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
          State: TDragState; var Accept: Boolean);
        procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

      TF1 = class(TForm1)

      end;

    var
      Form1: TForm1;

    implementation

    uses Unit2, Unit3;

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
      F2: TF1;
      F3: TForm1;
    begin
      f3 := f2;
    end;

    procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Button = mbleft then
        Edit1.BeginDrag(False, 10);
    end;

    procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
        if Button = mbleft then
        Label1.BeginDrag(False, 10);
    end;

    procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    begin
      if (Source = Label1) or (Source = Edit1) then
        Accept := True;
    end;

    procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
    begin
      if (Sender = ListBox1) and (Source = Label1) then
      begin
        ListBox1.Items.Add(TLabel(Source).Caption);
      end;

      if (Sender = ListBox1) and (Source = Edit1) then
      begin
        ListBox1.Items.Add(TEdit(Source).Text + ' haha ');
      end;
    end;

    end.

  • 相关阅读:
    Vim的分屏功能 | 酷壳 CoolShell.cn
    分享:Hadoop的Python框架指南
    KMP算法之另类图示分析
    C#cookie自动获取工具发布
    tmux Tutorial Split Terminal Windows Easily
    爱上MVC3~将系统的路由设置抽象成对象吧
    DDD~microsoft NLayerApp项目中的层次结构图
    不说技术~难得糊涂
    DDD~基础设施层
    基础才是重中之重~开发人员应用学会用throw
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/2193064.html
Copyright © 2011-2022 走看看