全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1158
推到 Plurk!
推到 Facebook!

有關Drag&Drop的問題

尚未結案
sophilelcy
一般會員


發表:3
回覆:0
積分:0
註冊:2003-11-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-11-14 16:59:01 IP:211.76.xxx.xxx 未訂閱
請問各位前輩有關Drag&Drop的問題 我建立兩個ListView,ListView1 和 ListView2, ListView1顯示目錄底下所有檔案. 我想要從ListView1拉檔案到ListView2要如何才能把檔案拉過去謝謝    底下是我的程式碼請各位前輩幫我     
//---------------------------------------------------------------------------
//Unit1.cpp
#include 
#pragma hdrstop    #include "Unit1.h"
#define TreeViewSelectedFullPath GetFullPath("",TreeView->Selected)
#define ListViewSelectedFullPath GetFullPath(ListView->Selected->Caption,TreeView->Selected)
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//#pragma message("test")
TPicViewForm *PicViewForm;
//---------------------------------------------------------------------------
__fastcall TPicViewForm::TPicViewForm(TComponent* Owner)
        : TForm(Owner)
{
        bCloseForm = false;
        Application->OnException = AppException;
}
//---------------------------------------------------------------------------
void __fastcall TPicViewForm::AppException(TObject *Sender,
      Exception *E)
{
        if(E->Message.Pos("I/O error 21"))
        {
                ShowMessage("Device " AnsiString(DriveComboBox1->Drive) " is not ready !");
                DriveComboBox1->Drive = DirectoryListBox1->Drive;
        }
}
//---------------------------------------------------------------------------
void __fastcall TPicViewForm::DirectoryListBox1Change(TObject *Sender)
{
        TListItem *ListItem;
        TSearchRec sr;
        TRect DRect,SRect;
        String AppDir=ExtractFileDir(Application->ExeName);
        //int iPicCount=0;
        int i;            ImageList1->Clear();
        ListView1->Items->Clear();            if(DirectoryListBox1->Directory.LastDelimiter("\\") == DirectoryListBox1->Directory.Length())
                DirectoryListBox1->Directory.SetLength(DirectoryListBox1->Directory.Length()-1);            if(!FindFirst(DirectoryListBox1->Directory "\\*.mp3", faAnyFile, sr))
        {
                do
                {
                        ListItem = ListView1->Items->Add();
                        ListItem->Caption = sr.Name;
                } while(FindNext(sr) == 0);
        }
}    //---------------------------------------------------------------------------
void __fastcall TPicViewForm::FormCloseQuery(TObject *Sender,
      bool &CanClose)
{
                bCloseForm = true;
}    //---------------------------------------------------------------------------
void __fastcall TPicViewForm::ListView2DragOver(TObject *Sender,
      TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
/*        if(dynamic_cast (Source))
                Accept = true;*/
}
//---------------------------------------------------------------------------    void __fastcall TPicViewForm::ListView1MouesDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
        TListItem *ListItem;
        TSearchRec sr;            ListView1->Selected = ListView1->GetItemAt(X,Y);
        if (ListView1->GetItemAt(X,Y) != NULL )
        {
                Application->MessageBox("This should be on top.", "Look", MB_OK);                    //THitTests MyHitTest = ListView1->GetHitTestInfoAt(X,Y);            ListItem = ListView2->Items->Add();
        ListItem->Caption = sr.Name;
        }
}
//---------------------------------------------------------------------------    //Unit1.h    #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//---------------------------------------------------------------------------
class TPicViewForm : public TForm
{
__published:        // IDE-managed Components
        TStatusBar *StatusBar1;
        TPanel *Panel2;
        TPanel *Panel3;
        TDriveComboBox *DriveComboBox1;
        TDirectoryListBox *DirectoryListBox1;
        TImageList *ImageList1;
        TListView *ListView1;
        TListView *ListView2;
        void __fastcall DirectoryListBox1Change(TObject *Sender);
        void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
        void __fastcall ListView2DragOver(TObject *Sender, TObject *Source,
          int X, int Y, TDragState State, bool &Accept);
        void __fastcall ListView1MouesDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
private:        // User declarations
        bool bCloseForm;
        void __fastcall AppException(TObject *Sender,Exception *E);
public:                // User declarations
        __fastcall TPicViewForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TPicViewForm *PicViewForm;
//---------------------------------------------------------------------------
#endif         
anpino
版主


發表:31
回覆:477
積分:231
註冊:2003-01-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-11-18 14:04:00 IP:218.32.xxx.xxx 未訂閱
sophilelcy您好: 若要ListView1拉檔案到ListView2,則 1. 兩個ListView的OnDragOver都要寫上 Accept = true; 2. 在ListView2的DragDrop中 使用CopyFileTo複製ListView1選到的檔名的檔案. 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D
anpino
版主


發表:31
回覆:477
積分:231
註冊:2003-01-02

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-06 16:05:45 IP:211.23.xxx.xxx 未訂閱
請回覆或結案。 ------------------------------- 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D -------------------------------
系統時間:2024-05-03 11:32:29
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!