C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[8031] 동적생성한 StaticText를 Panel위에서 이동시키기...
김소영 [qbuiler] 1824 읽음    2001-06-07 19:36


>>>>>>>>>>>>>Header 파일 <<<<<<<<<<<
//----------------------------------------------------------------------------
#ifndef ChildWinH
#define ChildWinH
//----------------------------------------------------------------------------
#include <vcl\Controls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\Graphics.hpp>
#include <vcl\Classes.hpp>
#include <vcl\Windows.hpp>
#include <vcl\System.hpp>
#include <StdCtrls.hpp>
#include <ExtCtrls.hpp>
//----------------------------------------------------------------------------
class TMDIChild : public TForm
{
__published:
        TPanel *Panel1;      //Panel on childform
   
        void __fastcall Panel1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);

   
private:

public:
    virtual __fastcall TMDIChild(TComponent *Owner);

        TStaticText *StaticText1;
        TLabel *Label2;
        int mDX,mDY;
        bool  isDown;

        void __fastcall Put_Indi(const AnsiString& unit,int X, int Y);
        void __fastcall StaticText1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
        void __fastcall StaticText1MouseMove(TObject *Sender,
          TShiftState Shift, int X, int Y);
        void __fastcall StaticText1MouseUp(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);

};
//----------------------------------------------------------------------------
#endif   


>>>>CPP파일<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "ChildWin.h"

//---------------------------------------------------------------------
#pragma resource "*.dfm"
//---------------------------------------------------------------------
__fastcall TMDIChild::TMDIChild(TComponent *Owner)
    : TForm(Owner)
{

isDown=false;

}
void __fastcall TMDIChild::Panel1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if(Button==mbLeft)

                Put_Indi("C",X,Y);
 

}
//---------------------------------------------------------------------
void __fastcall TMDIChild::Put_Indi(const AnsiString& unit,int X, int Y)
{

   Label2=new TLabel(this);
   StaticText1=new TStaticText(this);

   StaticText1->Parent=Panel1;
   Label2->Parent=Panel1;
   StaticText1->BorderStyle=sbsSingle;

   StaticText1->Caption="100000 "; 
   Label2->Caption=" "+unit;

   StaticText1->Font->Size=12;
   StaticText1->Font->Style = TFontStyles()<< fsBold;


   Label2->Color=Panel1->Color;

   StaticText1->Left=X;
   StaticText1->Top=Y;


   Label2->Left=X+StaticText1->Width;
   Label2->Top=Y;


}
//---------------------------------------------------------------------------
void __fastcall TMDIChild::StaticText1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  mDX=X;
  mDY=Y;
  isDown=true;
}
//---------------------------------------------------------------------------

void __fastcall TMDIChild::StaticText1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
if(isDown){

   StaticText1->Left=StaticText1->Left+X-mDX;
   StaticText1->Top=StaticText1->Top+Y-mDY;
   Label2->Left=Label2->Left+X-mDX;
   Label2->Top=Label2->Top+Y-mDY;
}
}
//---------------------------------------------------------------------------

void __fastcall TMDIChild::StaticText1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  isDown=false;
}
//---------------------------------------------------------------------------


아래 동작을 구현하려고 만든건데요.
1. Panel1 위에서 마우스를 Down하면 StaticText1과 Label2를 생성한다.
2. 생성된 StaticText1 위에서 마우스를 Down하고 Move하면 StaticText1과 Label2가 동시에 Panel 위에서
   이동한다.

위와같이 코딩하면 StaticText1와 Label2가 생성만 되고 이동은 안합니다.
그런데 이상한건 StaticText와 Label을 Panel에 미리 만들고 실행하면 StaticText와 Label이 Panel 위에서
이동하더군요. 도데체 뭐가 문젠지....-.-a
혹시 Panel위의 MouseDown이벤트 땜에 StaticText1의 마우스이벤트가 적용되지 않을 수 도 있나요?

그리고 StaticText의 MouseDown,MouseUp,MouseMove 이벤트를 Label에 코딩으로 연결(ObjetInspector에선
목록에서 선택하지요) 하는 방법도 알려주세요..

그럼 즐코하세여~~


+ -

관련 글 리스트
8031 동적생성한 StaticText를 Panel위에서 이동시키기... 김소영 1824 2001/06/07
8041     Re:동적생성한 StaticText를 Panel위에서 이동시키기... 경호 1456 2001/06/08
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.