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

在移動游標時要如何去判斷是否為子物件,及Disable事件

尚未結案
jackwu
一般會員


發表:28
回覆:54
積分:16
註冊:2002-08-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-04 13:47:07 IP:211.75.xxx.xxx 未訂閱
各位先進: 小弟之前有發表一篇自行製作的程式 【BCB】【發表】在Runtime時期可以改變元件的狀態及儲存  http://delphi.ktop.com.tw/topic.php?TOPIC_ID=61365    因為在程式中要去移動或者是改變元件的大小的方式過於麻煩(必須要按下所定義的方向鍵),所以想要改為比較方便的方法,就是利用滑鼠去做控制,小弟參考兩位大大所提供的程式: 【BCB】【發表】在執行期利用滑鼠任意移動元件  http://delphi.ktop.com.tw/topic.php?TOPIC_ID=43948 【BCB】【問題】有關 CompCtrl 元件的用法  http://delphi.ktop.com.tw/topic.php?topic_id=38601    我所撰寫的拖曳物件程式如下 其中DisplayForm就是我選定的Form     
 if(Msg.message==WM_MOUSEMOVE && !gbCanMove) // 改變游標的樣式及物件的大小
{
   GetCursorPos(&ScreenCursor);
   FocusCursor = dynamic_cast(DisplayForm)->ScreenToClient(ScreenCursor);
   FocusCtrl = dynamic_cast(DisplayForm)->ControlAtPos(FocusCursor, true, true); // 擷取到Form下的TControl物件
   if(FocusCtrl)
   {
      TPoint InCtrlCursorPos;
      GetCursorPos(&InCtrlCursorPos);
      InCtrlCursorPos = dynamic_cast(DisplayForm)->ScreenToClient(InCtrlCursorPos);
      if(InCtrlCursorPos.x < FocusCtrl->Left 5)
      {
         if(InCtrlCursorPos.y < FocusCtrl->Top 5)   FocusCtrl->Cursor = crSizeNWSE;
         else if(InCtrlCursorPos.y > FocusCtrl->Top FocusCtrl->Height-5) FocusCtrl->Cursor = crSizeNESW;
         else FocusCtrl->Cursor = crSizeWE;
      }
      else if(InCtrlCursorPos.x > FocusCtrl->Left FocusCtrl->Width-5)
      {
        if (InCtrlCursorPos.y < FocusCtrl->Top 5) FocusCtrl->Cursor = crSizeNESW;
        else if(InCtrlCursorPos.y > FocusCtrl->Top FocusCtrl->Height-5) FocusCtrl->Cursor = crSizeNWSE;
        else FocusCtrl->Cursor = crSizeWE;
      }
      else if ((InCtrlCursorPos.y < FocusCtrl->Top 5) || (InCtrlCursorPos.y > FocusCtrl->Top FocusCtrl->Height-5))
         FocusCtrl->Cursor = crSizeNS;
      else FocusCtrl->Cursor = crSizeAll;
   }
}
if(Msg.message==WM_MOUSEMOVE && gbCanMove && ScreenCtrl) // 移動物件
{
   GetCursorPos(&FocusCursor);
   int iXOffset=FocusCursor.x-ScreenCursor.x;
   int iYOffset=FocusCursor.y-ScreenCursor.y;
   int iLeft=ScreenControl.x iXOffset;
   int iTop=ScreenControl.y iYOffset;
   if(iLeft>0 && iLeft ScreenCtrl->Width<=dynamic_cast(DisplayForm)->Width)
   {
      ScreenCtrl->Left=iLeft;
   }
   if(iTop>=0 && iTop ScreenCtrl->Height<=dynamic_cast(DisplayForm)->Height)
   {
      ScreenCtrl->Top=iTop;
   }
}
if(Msg.message==WM_LBUTTONDOWN) // 選取物件
{
   gbCanMove=true;
   GetCursorPos(&ScreenCursor);
   FocusCursor = dynamic_cast(DisplayForm)->ScreenToClient(ScreenCursor);
   FocusCtrl = dynamic_cast(DisplayForm)->ControlAtPos(FocusCursor, true, true);
   if(FocusCtrl)
   {
      ScreenControl.x=FocusCtrl->Left;
      ScreenControl.y=FocusCtrl->Top;
      ScreenCtrl=FocusCtrl;
   }
}
if(Msg.message==WM_LBUTTONUP)
{
   gbCanMove=false;
   ScreenCtrl=NULL;
}
上述的程式已經可以做到指定一個Form並可以拖曳內部的元件。 問題一: ControlAtPos的Function只能夠擷取到所指定物件的Child Control,但如果在此Form下有一個類似TPanel物件,其中可以放置其他的TControl物件(ex.TButton)的話,我就無法對於TPanel內的物件做控制,請問各位先進,這樣的程式應該要怎麼改才行呢? 問題二: 我要如何將滑鼠所指到的物件其相對應的 >
jackwu
一般會員


發表:28
回覆:54
積分:16
註冊:2002-08-18

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-06 19:34:46 IP:211.75.xxx.xxx 未訂閱
各位先進: 看來好像都沒有人可以回答我的問題,不過我已經將攔截滑鼠訊息的方式修改,直接在我所繼承的Class中覆寫滑鼠的事件  
 class TFocusComponent : public TControl
{
//將TControl底下protected內的屬性變為public
public:
   __property Color;
   __property Font;
   __property Caption;
   __property OnMouseDown ;
   __property OnMouseMove ;
   __property OnMouseUp ;
   __property OnClick ;
};
詳細的程式碼我已經放在 【BCB】【發表】在Runtime時期可以改變元件的狀態及儲存Part2-UseMouse http://delphi.ktop.com.tw/topic.php?topic_id=31557 請各位先進指教囉! 發表人 -
jackwu
一般會員


發表:28
回覆:54
積分:16
註冊:2002-08-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-09 12:11:53 IP:211.75.xxx.xxx 未訂閱
各位先進: 經由RedSnow大大的指正,我所放的連結有所錯誤,現在已經改正 造成各位的不便,深感抱歉 連結如下: 【BCB】【發表】在Runtime時期可以改變元件的狀態及儲存Part2-UseMouse http://delphi.ktop.com.tw/topic.php?TOPIC_ID=63002
系統時間:2024-04-24 11:48:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!