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);

  • 相关阅读:
    Oracle 11g alert log 新增消息 opiodr aborting process unknown ospid (1951) as a result of ORA28 说明
    Oracle 11g alert log 新增消息 opiodr aborting process unknown ospid (1951) as a result of ORA28 说明
    Oracle RAC 第二节点 root.sh 报错 Timed out waiting for the CRS stack to start
    tlq tonglink/q 常用管理方法
    linux分区
    Tuxedo中间件 配置维护记录
    linux后台执行
    tuxedo 常见问题总结
    linux netstat nr route
    sybase 性能监控及调优(转)
  • 原文地址:https://www.cnblogs.com/jijm123/p/11106181.html
Copyright © 2011-2022 走看看