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

請問一下有沒有更好的方法撰寫產生動態的元件

 
logi
一般會員


發表:4
回覆:4
積分:1
註冊:2002-10-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-16 13:39:59 IP:220.142.xxx.xxx 未訂閱
1.有什麼好的方式將一些元件放在groupbox上 2.假設我想要用建各自各function去產生一些元件...並配置位置或大小    例如    void Create_Label(XXX);    void Create_Group(XXX);    void Create_Edit(XXX);    要如何傳元件的位址給function使用 3.或者前輩們有更好的方式...可以提供參考... thanks        void __fastcall TForm1::FormCreate(TObject *Sender) {    TGroupBox *temp;    TLabel *s;       for(int i=0; i<6; i ) { temp = new TGroupBox(this); temp->Name = "GroupBox" IntToStr(i); temp->Parent = this; switch(i) { case 0 : temp->Caption = "請選擇位址"; temp->Top = 10; temp->Left = 10; temp->Width = 300; temp->Height = 150; for(int i=0; i<2; i ) { (TLabel*) s = new TLabel(this); s->Name = "Label" IntToStr(i); s->Parent = temp; switch(i) { case 0 : s->Caption = "第一個8255的位址 :"; s->Top = 40; s->Left = 40; s->Width = 100; s->Height = 20; break; case 1 : s->Caption = "第二個8255的位址 :"; s->Top = 60; s->Left = 40; s->Width = 100; s->Height = 20; break; } //switch } break; case 1 : temp->Caption = "控制位元"; temp->Top = 10; temp->Left = 320; temp->Width = 300; temp->Height = 150; break; case 2 : temp->Caption = "第一個8255 I/O設定"; temp->Top = 170; temp->Left = 10; temp->Width = 300; temp->Height = 150; break; case 3 : temp->Caption = "第二個8255 I/O設定"; temp->Top = 170; temp->Left = 320; temp->Width = 300; temp->Height = 150; break; case 4 : temp->Caption = "第一個8255 I/O值"; temp->Top = 330; temp->Left = 10; temp->Width = 300; temp->Height = 150; break; case 5 : temp->Caption = "第二個8255 I/O值"; temp->Top = 330; temp->Left = 320; temp->Width = 300; temp->Height = 150; break; } //switch } }
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-16 15:07:49 IP:211.76.xxx.xxx 未訂閱
logi 您好:    我習慣於將資料與實作部份分開,這樣要修改時較方便。    
1.建議先自行定義一個結構:    struct ComponentData
{ char caption[50];
  int top, left, width, height;
};    2.資料存在陣列中或由檔案讀入,    ComponentData myData[]=
{ {"請選擇位址",10,10,300,150},
  {"第一個8255的位址 :", 40,40,100,20}
};    3.利用迴圈動態建立元件,    void __fastcall TForm1::Button1Click(TObject *Sender)
{ TGroupBox *temp;
  for(int i=0; i<6; i  )
  { temp = new TGroupBox(this);
    temp->Name = "GroupBox"   IntToStr(i);
    temp->Parent = this;        temp->Caption = myData[i].caption;
    temp->Top     = myData[i].top;
    temp->Left    = myData[i].left;
    temp->Width   = myData[i].width;
    temp->Height  = myData[i].height;
  }
}
//--------------------------------------------------------------------------- 
提供參考!
系統時間:2024-05-19 8:13:01
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!