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

有關drag-drop問題??

答題得分者是:RaynorPao
hjlin
一般會員


發表:63
回覆:48
積分:22
註冊:2003-02-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-12 00:10:46 IP:61.230.xxx.xxx 未訂閱
請問一下,我寫了一個拖放功能,但感覺非常不靈敏,請問一下有無比較好的function可以參考的??
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-12 00:35:35 IP:61.224.xxx.xxx 未訂閱
hjlin 你好, 這裡有一個bcb online help的範例,你可以參考一下,    首先先在Form中加入三個Label和一個ListBox    再加以下程式碼: 就可把Label的color和font拉到ListBox裡去了, 我只有寫color,font你可以自己試試     
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   Label1->Color=clRed;
   Label1->DragMode=dmAutomatic;       Label2->Color=clBlue;
   Label2->DragMode=dmAutomatic;       Label3->Color=clGreen;
   Label3->DragMode=dmAutomatic;       ListBox1->Color=clWhite;    }
//----------------------------------------------------------------    void __fastcall TForm1::ListBox1DragDrop(TObject *Sender, TObject *Source,
      int X, int Y)
{
    if (Sender->ClassNameIs("TListBox") && Source->ClassNameIs("TLabel"))
  {
    TListBox *DestList = (TListBox *)Sender;
    DestList->Font = ((TLabel *)Source)->Font;
    DestList->Color = ((TLabel *)Source)->Color;
  }    }
//-----------------------------------------------------------------
void __fastcall TForm1::ListBox1DragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
    Accept = Source->ClassNameIs("TLabel");
}
//-----------------------------------------------------------------     
國泰平安
renth555
一般會員


發表:32
回覆:65
積分:19
註冊:2003-02-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-12 21:45:49 IP:61.56.xxx.xxx 未訂閱
可以請前輩幫我說明語法嗎    if(Sender->ClassNameIs("TListBox") && Source->ClassNameIs("TLabel")) {      TListBox *DestList = (TListBox *)Sender;      DestList->Font = ((TLabel *)Source)->Font;      DestList->Color = ((TLabel *)Source)->Color; }         Accept = Source->ClassNameIs("TLabel"); 1. ClassNameIs("TListBox") 2. TListBox *DestList = (TListBox *)Sender; 3. ((TLabel *)Source) 不懂他的定義方法 當(目的地物件)偵測到有(來源物件)碰撞時觸發事件 ListBox1DragDrop(TObject *Sender, TObject *Source, int X, int Y) 這個我不是很了解 ListBox1DragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept) 請前輩們教導
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-07-12 22:48:52 IP:61.224.xxx.xxx 未訂閱
renth555你好,     
引言: 1. ClassNameIs("TListBox") ClassNameIs()是bool型態,用來判斷是Class的name,傳回true或false 2. TListBox *DestList = (TListBox *)Sender; 這是把Sender這個指標用TListBox來套,來給DestList這個TListBox指標用, 這樣就能把Sender轉為TListBox的結構指標了,就能使用ListBox的property 3. ((TLabel *)Source) 同上,不過是用TLabel來套。 ----------------------------------------------- 當(目的地物件)偵測到有(來源物件)碰撞時觸發事件 ListBox1DragDrop(TObject *Sender, TObject *Source, int X, int Y) 你可以去查bcb的online help,查onDragDrop,上面有說, 這四個參數,是你使用這個function,或是而這個動作, 他會傳進來的參數, TObject *Sender 這個我不太會解釋, 之前有幾篇有講到,我再幫你找找,是很基本的東西, 就像是你程式到那,Sender就會跟著到那... 但越是基本的東西,越是要謹慎,我怕一個小地方說錯,就不好了。 聽聽那些厲害的前輩說說好了,哈 TObject *Source 是你拉過來的東西, int x 和y 就是你拉過來的東西的座標, ListBox1DragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept) 這只是多了兩個參數, 一個是 State,是一個TDragState, 裡面的值會是下面三個value中的一個, 分別是dsDragEnter, dsDragLeave, dsDragMove 看字意大約就懂一半了吧, 最後一個是Accept 如果為true就接受這個動作,為false就拒絕。 回的很趕,因為等會我還有事要忙,想說怕你等太久, 所以如果有錯的話, 請其他前輩幫小弟糾正一下,謝謝了 最好是多多查查>< face="Verdana, Arial, Helvetica"> 國泰平安 發表人 - gemi0305 於 2003/07/12 22:50:40 發表人 - gemi0305 於 2003/07/13 01:32:52
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-07-13 01:30:29 IP:61.224.xxx.xxx 未訂閱
renth555你好, 我再補充一下,讓你更清楚,    1. ClassNameIs("TListBox") ClassNameIs()是bool型態,用來判斷是Class的name,傳回true或false 如:Accept=Source->ClassNameIs("TLabel"); 如果Source的ClassName是TLabel, Acccept的值就會為true。    2. TListBox *DestList = (TListBox *)Sender; 因為不知道進來的會是誰(Sender),就把Sender這個指標用TListBox來套, 並設給一個TListBox型態的DestList, DestList是一個TListBox,但他的值是Sender裡的值。 所以簡單的說就是: Sender先把自已轉成TListBox結構後,再把值複製給DestList。    3. ((TLabel *)Source) 懂2之後,這就沒問題了    ListBox1DragDrop(TObject *Sender, TObject *Source, int X, int Y)    Sender  可以去看看這篇文章 http://delphi.ktop.com.tw/topic.php?topic_id=33065    以上為小補充一下,如果還是有點不懂,大家再來討論, 因為我還是個肉腳,所以請多多包涵啦~ 國泰平安
renth555
一般會員


發表:32
回覆:65
積分:19
註冊:2003-02-17

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-07-13 04:15:13 IP:61.56.xxx.xxx 未訂閱
先謝謝前輩指導 我現在是拖移 Label1 --到--> ListBox1 當移到 ListBox1 物件上就觸發事件傳入 ---- 是所謂(寄件人) = ListBox1DragDrop(自己) | | V ListBox1DragDrop(TObject *Sender, TObject *Source, int X, int Y) | | | | 同時也傳入 來源物件 Label1 是這樣嗎 <--| 意思是,Label1 移動到 ListBox1 物件上而 ListBox1 便自己觸發傳入自己參數 跟 我按 ListBox1->OnClock 的觸發 意義相同是嗎 自己所理解的做這樣解釋請前輩幫我指導那裡關念錯誤
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-07-13 10:48:32 IP:61.224.xxx.xxx 未訂閱
renth555你好 沒錯,很多 > 國泰平安
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-07-14 22:16:23 IP:61.221.xxx.xxx 未訂閱
引言: 請問一下,我寫了一個拖放功能,但感覺非常不靈敏,請問一下有無比較好的function可以參考的??
hjlin 你好: 試試看這樣子做,行不行呢?? < class="code"> bool gbCanMove=false; int giX=0; int giY=0; void __fastcall TForm1::Image4MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { gbCanMove=true; giX=X; giY=Y; } void __fastcall TForm1::Image4MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { gbCanMove=false; } void __fastcall TForm1::Image4MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int iXOffset=X-giX; int iYOffset=Y-giY; if(gbCanMove) { if(Image4->Left iXOffset<Form1->ClientRect.Left) { Image4->Left=0; } else if(Image4->Left Image4->Width iXOffset>Form1->ClientRect.Right) { Image4->Left=Form1->ClientRect.Right-Image4->Width; } else { Image4->Left =iXOffset; } if(Image4->Top iYOffset<Form1->ClientRect.Top) { Image4->Top=0; } else if(Image4->Top Image4->Height iYOffset>Form1->ClientRect.Bottom) { Image4->Top=Form1->ClientRect.Bottom-Image4->Height; } else { Image4->Top =iYOffset; } } } void __fastcall TForm1::FormCreate(TObject *Sender) { Form1->DoubleBuffered=true; } -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-07-15 00:05:55 IP:61.224.xxx.xxx 未訂閱
此版大家都是很熱心的, 一個問題的解決,是靠著許多互動,慢慢明瞭問題, 最後找出最好的答案, 不是只將問題丟出,大家就清楚知道你的想問的一切, 方要別人拉自己一把,自己是否該當伸出手來呢 也不是用許多的相同文章版面,讓你的問題更容易被大家看到, 這只會造成大家的模糊... 一個值得大家討論的問題,只需要一篇, 就能讓大家討論的淋淋盡致,彼此各有所獲, 請好好珍惜大家的熱心... 我是對事而談,並無他意 國泰平安
hjlin
一般會員


發表:63
回覆:48
積分:22
註冊:2003-02-11

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-07-15 09:54:26 IP:61.56.xxx.xxx 未訂閱
我的問題如下: 1. 我發覺 Imag2 利用 Mouse_up-Mouse_down 的方法好像只能上下移動說,不能左右移動嗎?(我需要能左右移動的) 2. 當我調整好 Image2 (前景) 後,我希望 save 此張我所想要的前景與背景的空間擺設位置圖...但請看下面結果 可否請大家幫我看看,要如何解決這兩個問題,程式如下 //--------------------------------------------------------------------------- #include #pragma hdrstop #include "SPE.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; bool gbCanMove=false; int giX=0; int giY=0; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Edit2->Text = ""; Edit3->Text = ""; } //--------------------------------------------------------------------------- void __fastcall TForm1::BGFile1Click(TObject *Sender) { Image1->Width=256; Image1->Height=224; Image1->Stretch=true; Image1->Picture->Bitmap->LoadFromFile("back.bmp"); //ShowMessage("1"); } //--------------------------------------------------------------------------- void __fastcall TForm1::SPFile1Click(TObject *Sender) { Image2->Width=100; Image2->Height=123; Image2->Stretch=true; Image2->Picture->Bitmap->LoadFromFile("fore.bmp"); } //--------------------------------------------------------------------------- void __fastcall TForm1::Save_btnClick(TObject *Sender) { Image3->Width=Image1->Width; Image3->Height=Image1->Height; Image3->Stretch=true; Image3->Canvas->CopyMode=cmSrcCopy; SetStretchBltMode(Image3->Canvas->Handle, STRETCH_HALFTONE); Image3->Canvas->CopyRect(Rect(0, 0, Image3->Width, Image3->Height), Image1->Canvas, Rect(0, 0, Image1->Width, Image1->Height)); //ShowMessage("4"); Image4->Width=Image2->Width; Image4->Height=Image2->Height; //Image4->Left=Image3->Left; Image4->Left=Image3->Left+50; //Image4->Top=Image3->Top; Image4->Top=Image3->Top+50; Image4->Stretch=true; Image4->Canvas->CopyMode=cmSrcCopy; SetStretchBltMode(Image4->Canvas->Handle, STRETCH_HALFTONE); Image4->Canvas->CopyRect(Rect(0, 0, Image4->Width, Image4->Height), Image2->Canvas, Rect(0, 0, Image2->Width, Image2->Height)); Image4->Picture->Bitmap->TransparentColor=clWhite; Image4->Transparent=true; Application->ProcessMessages(); //ShowMessage("5"); TPoint ptLT1, ptRB1, ptLT2, ptRB2; ptLT1.x=Image3->Left; ptLT1.y=Image3->Top; ptRB1.x=Image3->Left+Image3->Width; ptRB1.y=Image3->Top+Image3->Height; ptLT2=Form1->ClientToScreen(ptLT1); ptRB2=Form1->ClientToScreen(ptRB1); HDC dc; dc=GetDC(0); TCanvas *canvas=new TCanvas; canvas->Handle=dc; Graphics::TBitmap *bmp=new Graphics::TBitmap; bmp->Width=Image3->Width; bmp->Height=Image3->Height; bmp->Canvas->CopyMode=cmSrcCopy; //ShowMessage("6"); SetStretchBltMode(bmp->Canvas->Handle, STRETCH_HALFTONE); bmp->Canvas->CopyRect(Rect(0, 0, bmp->Width, bmp->Height), canvas, Rect(ptLT2.x, ptLT2.y, ptRB2.x, ptRB2.y)); bmp->SaveToFile("merge.bmp"); //ShowMessage("7"); delete bmp; delete canvas; ReleaseDC(NULL, dc); } //--------------------------------------------------------------------------- void __fastcall TForm1::Image2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { gbCanMove=true; giX=X; giY=Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { gbCanMove=false; } //--------------------------------------------------------------------------- void __fastcall TForm1::Image2MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int iXOffset=X-giX; int iYOffset=Y-giY; if(gbCanMove) { if(Image2->Left+iXOffset < Form1->ClientRect.Left) { Image2->Left=0; } else if(Image2->Left+Image2->Width+iXOffset > Form1->ClientRect.Right) { Image2->Left+=iXOffset; } if(Image2->Top+iYOffset < Form1->ClientRect.Top) { Image2->Top=0; } else if(Image2->Top+Image2->Height+iYOffset > Form1->ClientRect.Bottom) { Image2->Top=Form1->ClientRect.Bottom-Image2->Height; } else { Image2->Top+=iYOffset; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Form1->DoubleBuffered=true; } //---------------------------------------------------------------------------
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-07-15 10:11:53 IP:203.73.xxx.xxx 未訂閱
引言: 我的問題如下: 1. 我發覺 Imag2 利用 Mouse_up-Mouse_down 的方法好像只能上下移動說,不能左右移動嗎?(我需要能左右移動的) 2. 當我調整好 Image2 (前景) 後,我希望 save 此張我所想要的前景與背景的空間擺設位置圖...但請看下面結果
hjlin 你好: 我的完整程式碼如下,你再依照自己的需求更改吧(不會有你說的那兩個問題)
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   Image1->Width=256;
   Image1->Height=224;
   Image1->Stretch=true;
   Image1->Picture->Bitmap->LoadFromFile("back.bmp");       Image2->Width=100;
   Image2->Height=123;
   Image2->Stretch=true;
   Image2->Picture->Bitmap->LoadFromFile("fore.bmp");       Image3->Width=Image1->Width;
   Image3->Height=Image1->Height;
   Image3->Stretch=true;
   Image3->Canvas->CopyMode=cmSrcCopy;
   SetStretchBltMode(Image3->Canvas->Handle, STRETCH_HALFTONE);
   Image3->Canvas->CopyRect(Rect(0, 0, Image3->Width, Image3->Height),
      Image1->Canvas, Rect(0, 0, Image1->Width, Image1->Height));       Image4->Width=Image2->Width;
   Image4->Height=Image2->Height;
//   Image4->Left=Image3->Left 50;
//   Image4->Top=Image3->Top 50;
   Image4->Stretch=true;
   Image4->Canvas->CopyMode=cmSrcCopy;
   SetStretchBltMode(Image4->Canvas->Handle, STRETCH_HALFTONE);
   Image4->Canvas->CopyRect(Rect(0, 0, Image4->Width, Image4->Height),
      Image2->Canvas, Rect(0, 0, Image2->Width, Image2->Height));
   Image4->Picture->Bitmap->TransparentColor=clWhite;
   Image4->Transparent=true;
   Application->ProcessMessages();       TPoint ptLT1, ptRB1, ptLT2, ptRB2;
   ptLT1.x=Image3->Left;
   ptLT1.y=Image3->Top;
   ptRB1.x=Image3->Left Image3->Width;
   ptRB1.y=Image3->Top Image3->Height;
   ptLT2=Form1->ClientToScreen(ptLT1);
   ptRB2=Form1->ClientToScreen(ptRB1);       HDC dc;
   dc=GetDC(0);
   TCanvas *canvas=new TCanvas;
   canvas->Handle=dc;
   Graphics::TBitmap *bmp=new Graphics::TBitmap;
   bmp->Width=Image3->Width;
   bmp->Height=Image3->Height;
   bmp->Canvas->CopyMode=cmSrcCopy;
   SetStretchBltMode(bmp->Canvas->Handle, STRETCH_HALFTONE);
   bmp->Canvas->CopyRect(Rect(0, 0, bmp->Width, bmp->Height),
      canvas, Rect(ptLT2.x, ptLT2.y, ptRB2.x, ptRB2.y));
   bmp->SaveToFile("merge.bmp");
   delete bmp;
   delete canvas;
   ReleaseDC(NULL, dc);
}
bool gbCanMove=false;
int giX=0;
int giY=0;
void __fastcall TForm1::Image4MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
   gbCanMove=true;
   giX=X;
   giY=Y;
}
void __fastcall TForm1::Image4MouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
   gbCanMove=false;
}
void __fastcall TForm1::Image4MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
   int iXOffset=X-giX;
   int iYOffset=Y-giY;
   if(gbCanMove)
   {
      if(Image4->Left iXOffset<Form1->ClientRect.Left)
      {
         Image4->Left=0;
      }
      else if(Image4->Left Image4->Width iXOffset>Form1->ClientRect.Right)
      {
         Image4->Left=Form1->ClientRect.Right-Image4->Width;
      }
      else
      {
         Image4->Left =iXOffset;
      }
      if(Image4->Top iYOffset<Form1->ClientRect.Top)
      {
         Image4->Top=0;
      }
      else if(Image4->Top Image4->Height iYOffset>Form1->ClientRect.Bottom)
      {
         Image4->Top=Form1->ClientRect.Bottom-Image4->Height;
      }
      else
      {
         Image4->Top =iYOffset;
      }
   }
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Form1->DoubleBuffered=true;
}
-- Enjoy Researching & Developing -- 發表人 - RaynorPao 於 2003/07/15 10:32:32
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
系統時間:2024-04-29 2:55:47
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!