zoukankan      html  css  js  c++  java
  • ListView中用鼠标拖动各项上下移动的问题。(100分)

    在OnDragDrop事件中處理:
    以下是delphi的例子

    procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);

    begin
    Accept := Source is TLabel;

    end;

    This OnDragDrop event handler implements the drop behavior.

    procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);

    begin
    if (Sender is TListBox) and (Source is TLabel) then
    begin
    with Sender as TListBox do
    begin
    Font := (Source as TLabel).Font;
    Color := (Source as TLabel).Color;
    end;
    end;
    end;

    但如果将Drag设为TRUE
    就会出现难看的鼠标残影
    怎样去掉?

    下面这个是LISTBOX1的,都差不多的,你参考一下看看吧
    要声明一个窗体级以上的变量oldrect:Trect;,可以加在private下面

    procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;
    State: TDragState; var Accept: Boolean);
    begin
    //这是让FORM接受从LISTBOX里拖出的动作,注意要个FORM留出空间在外面
    if source=listbox1 then
    accept:=true;
    end;

    procedure TForm1.ListBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
    begin
    if (target<>nil)and(target.ClassName<>sender.ClassName) then
    listbox1.Items.Delete(listbox1.itemindex);
    if target=nil then
    listbox1.Canvas.DrawFocusRect(oldrect);
    oldrect.Bottom:=0; //拖放完之后把矩形变量清空
    end;

    procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
    State: TDragState; var Accept: Boolean);
    var
    mypos:Tpoint;
    begin
    if source=listbox1 then
    accept:=true;
    mypos.x:=x;
    mypos.y:=y;
    if listbox1.ItemAtPos(mypos,true)<>-1 then
    begin 
    listbox1.Canvas.DrawFocusRect(oldrect); //通过‘异或’去掉上次的框框
    listbox1.Canvas.DrawFocusRect(listbox1.ItemRect(listbox1.ItemAtPos(mypos,true)));//画上本次的框框
    oldrect:=listbox1.ItemRect(listbox1.ItemAtPos(mypos,true));
    end;

    end;

    procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
    var
    P_move:Tpoint;
    begin
    {通过坐标获得ITEM}
    P_move.x:=x;
    p_move.y:=y;

    if (listbox1.itemindex<>-1) and (listbox1.ItemAtPos(P_move,true)<>-1) then
    //这一句可以替换上次那几句
    listbox1.Items.Exchange(listbox1.itemindex,listbox1.ItemAtPos(P_move,true));//互换ITEM

    //下面一句也是拖放不成功的时候要去掉最后画的那个FOCUS框
    if listbox1.ItemAtPos(P_move,true)=-1 then
    listbox1.Canvas.DrawFocusRect(oldrect);

  • 相关阅读:
    计算几何——交点、面积的计算
    计算几何——认识基本object:点、线、面 。
    图的拓扑排序——卡恩算法
    Manacher
    如何不改造 HBase 就能应对复杂查询场景
    如何做沟通
    大数据磁盘阵列技术
    Android系统架构开篇
    Apache Kylin 原理介绍与新架构分享(Kylin On Parquet)
    遭遇突然提问慌了?掌握关键2点完美应对zz
  • 原文地址:https://www.cnblogs.com/jijm123/p/11106181.html
Copyright © 2011-2022 走看看