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.

  • 相关阅读:
    python学习--函数
    python学习--变量
    python学习--运算符
    python学习--数据类型
    python学习--循环语句
    年轻不言失败
    《zero to one》读后感
    进程与线程
    JS----模块化
    js 一个等号"=" 二个等号"==" 三个等号"===" object.is()的区别
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/2193064.html
Copyright © 2011-2022 走看看