JPTseng
一般會員
發表:14 回覆:22 積分:7 註冊:2004-10-27
發送簡訊給我
|
以下是一個動態"貼圖"的程式~~但是無法"作用"
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,TShiftState Shift, int X, int Y)
{ Image1->Left=X;
Image1->Top=Y;
} 但是請問有可以動態"產生Button" 的指令嗎 ?
(產生出來的Button必須可以用mouse-press來完成其他工作)
|
seeing
初階會員
發表:49 回覆:131 積分:41 註冊:2002-11-07
發送簡訊給我
|
您好:
可以參考以下連結
http://delphi.ktop.com.tw/topic.php?topic_id=37960 p.s. 請善用版上的「搜尋」功能
|
Zard
尊榮會員
發表:24 回覆:396 積分:539 註冊:2003-11-26
發送簡訊給我
|
引言:
以下是一個動態"貼圖"的程式~~但是無法"作用"
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,TShiftState Shift, int X, int Y)
{ Image1->Left=X;
Image1->Top=Y;
} 但是請問有可以動態"產生Button" 的指令嗎 ?
(產生出來的Button必須可以用mouse-press來完成其他工作)
下面的碼是動態產生按鈕後, 按該按鈕會進行貼圖的動作
//---------------------------------------------------------------------------
// Unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormDestroy(TObject *Sender); private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner); void __fastcall MyButtonClick(TObject *Sender);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
// Unit1.cpp
#include
#pragma hdrstop #include "Unit1.h" //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1; TButton *MyButton;
TImage *MyImage; __fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
MyButton = new TButton(this);
MyButton->Left = 10;
MyButton->Top = 10;
MyButton->Caption = "貼上圖片";
MyButton->OnClick = &MyButtonClick;
MyButton->Visible = TRUE; Form1->InsertControl(MyButton); MyImage = NULL;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::MyButtonClick(TObject *Sender)
{
if (MyImage)
{
MyImage->Free();
MyImage = NULL; MyButton->Caption = "貼上圖片";
}
else
{
MyImage = new TImage(this);
MyImage->Left = 50;
MyImage->Top = 50;
MyImage->AutoSize = TRUE;
MyImage->Picture->LoadFromFile("c:\\1.bmp");
MyImage->Visible = TRUE;
Form1->InsertControl(MyImage); MyButton->Caption = "移除圖片";
}
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormDestroy(TObject *Sender)
{
if (MyButton) MyButton->Free();
}
//---------------------------------------------------------------------------
|
JPTseng
一般會員
發表:14 回覆:22 積分:7 註冊:2004-10-27
發送簡訊給我
|
引言:
您好:
可以參考以下連結
http://delphi.ktop.com.tw/topic.php?topic_id=37960 p.s. 請善用版上的「搜尋」功能
>>< face="Verdana, Arial, Helvetica"> 很抱歉~~你這是"已經產生"~~而非我所指的
我的意思是需要點到Form上之後,再產生出來!!
|
JPTseng
一般會員
發表:14 回覆:22 積分:7 註冊:2004-10-27
發送簡訊給我
|
引言:
下面的碼是動態產生按鈕後, 按該按鈕會進行貼圖的動作
//---------------------------------------------------------------------------
// Unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormDestroy(TObject *Sender); private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner); void __fastcall MyButtonClick(TObject *Sender);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif //---------------------------------------------------------------------------
// Unit1.cpp
#include
#pragma hdrstop #include "Unit1.h" //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1; TButton *MyButton;
TImage *MyImage; __fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
MyButton = new TButton(this);
MyButton->Left = 10;
MyButton->Top = 10;
MyButton->Caption = "貼上圖片";
MyButton->OnClick = &MyButtonClick;
MyButton->Visible = TRUE; Form1->InsertControl(MyButton); MyImage = NULL;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::MyButtonClick(TObject *Sender)
{
if (MyImage)
{
MyImage->Free();
MyImage = NULL; MyButton->Caption = "貼上圖片";
}
else
{
MyImage = new TImage(this);
MyImage->Left = 50;
MyImage->Top = 50;
MyImage->AutoSize = TRUE;
MyImage->Picture->LoadFromFile("c:\\1.bmp");
MyImage->Visible = TRUE;
Form1->InsertControl(MyImage); MyButton->Caption = "移除圖片";
}
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormDestroy(TObject *Sender)
{
if (MyButton) MyButton->Free();
}
//---------------------------------------------------------------------------
[/quote]
我想先問一下我其中不懂的問題
1. 在您的 Unit1.h 下列這兩項是要自己手動打嗎 ?
void __fastcall FormDestroy(TObject *Sender);
void __fastcall MyButtonClick(TObject *Sender);
2. 在您的 Unit1.cpp 中下列這兩項是如何產生?
void __fastcall TForm1::MyButtonClick(TObject *Sender)
void __fastcall TForm1::FormDestroy(TObject *Sender) 謝謝您的回答~~~^^
< >< >
|
Zard
尊榮會員
發表:24 回覆:396 積分:539 註冊:2003-11-26
發送簡訊給我
|
引言:
我想先問一下我其中不懂的問題
1. 在您的 Unit1.h 下列這兩項是要自己手動打嗎 ?
void __fastcall FormDestroy(TObject *Sender);
void __fastcall MyButtonClick(TObject *Sender);
2. 在您的 Unit1.cpp 中下列這兩項是如何產生?
void __fastcall TForm1::MyButtonClick(TObject *Sender)
void __fastcall TForm1::FormDestroy(TObject *Sender) 謝謝您的回答~~~^^
< >< >
>>< face="Verdana, Arial, Helvetica"> MyButtonClick是要自己加上去的, 因為這是你的動態按鈕所要的觸事件, BCB無法自動幫你產生. FormDestroy是由BCB自動產生的, 就像FormCreate或FormMouseDown一樣, 就是Form1的事件中的OnDestroy, 點兩下OnDestroy BCB 就會自動產生
|
JPTseng
一般會員
發表:14 回覆:22 積分:7 註冊:2004-10-27
發送簡訊給我
|
MyButtonClick是要自己加上去的, 因為這是你的動態按鈕所要的觸事件, BCB無法自動幫你產生.
FormDestroy是由BCB自動產生的, 就像FormCreate或FormMouseDown一樣, 就是Form1的事件中的OnDestroy, 點兩下OnDestroy BCB 就會自動產生
[/quote] 非常謝謝你的熱心回答~~~^^
|