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

動態產生 Button ?

答題得分者是:Zard
JPTseng
一般會員


發表:14
回覆:22
積分:7
註冊:2004-10-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-31 11:38:10 IP:140.124.xxx.xxx 未訂閱
以下是一個動態"貼圖"的程式~~但是無法"作用" 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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-10-31 11:47:56 IP:140.134.xxx.xxx 未訂閱
您好:     可以參考以下連結     http://delphi.ktop.com.tw/topic.php?topic_id=37960        p.s. 請善用版上的「搜尋」功能
Zard
尊榮會員


發表:24
回覆:396
積分:539
註冊:2003-11-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-10-31 11:59:48 IP:61.64.xxx.xxx 未訂閱
引言: 以下是一個動態"貼圖"的程式~~但是無法"作用" 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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-10-31 12:08:38 IP:140.124.xxx.xxx 未訂閱
引言: 您好: 可以參考以下連結 http://delphi.ktop.com.tw/topic.php?topic_id=37960 p.s. 請善用版上的「搜尋」功能 < face="Verdana, Arial, Helvetica"> 很抱歉~~你這是"已經產生"~~而非我所指的 我的意思是需要點到Form上之後,再產生出來!!
JPTseng
一般會員


發表:14
回覆:22
積分:7
註冊:2004-10-27

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-10-31 12:28:50 IP:140.124.xxx.xxx 未訂閱
引言:
下面的碼是動態產生按鈕後, 按該按鈕會進行貼圖的動作
//---------------------------------------------------------------------------
// 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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-10-31 12:35:09 IP:61.64.xxx.xxx 未訂閱
引言: 我想先問一下我其中不懂的問題 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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-10-31 12:51:48 IP:140.124.xxx.xxx 未訂閱
MyButtonClick是要自己加上去的, 因為這是你的動態按鈕所要的觸事件, BCB無法自動幫你產生. FormDestroy是由BCB自動產生的, 就像FormCreate或FormMouseDown一樣, 就是Form1的事件中的OnDestroy, 點兩下OnDestroy BCB 就會自動產生 [/quote] 非常謝謝你的熱心回答~~~^^
系統時間:2024-06-28 1:51:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!