最近遇到一个问题,如果通过读取数据库来动态的生成窗体,并在窗体上动态生成label和edit,如何将他们顺序的排列在窗体上?

解决方案 »

  1.   

    这跟你的Label和Edit的最大长度有关。
    以下源代码可供参考:
    生成从左到右的三排SpeedButton.
        for i:=0 to 29 do
        begin
          spdButton:=TSpeedButton.Create(Panel26);
          with spdButton do
          begin
            Height:=sbWordEdit.Height;  //高度
            Width:=sbWordEdit.Width;    //宽度
            Caption:=trim(IntToStr(i));
            Layout:=sbWordEdit.Layout;
            Parent:=Panel26;
            OnClick:=sbWordEdit.OnClick;
            Top:=10+Height*(i div 3);     
            Left:=16+Width*(i Mod 3);     
          end;
        end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      iFHeigh : Integer;
      iLab,icount : Integer;
      LLab : TLabel;
    begin
      iFHeigh := Form1.Height;
      for iCount := 0 to 10 do
      begin
        lLab := TLabel.Create(Self);
        lLab.Caption := '第'+IntToStr(iCount)+'个';
        lLab.Top := iCount * (iFHeigh div 10);
        lLab.Left := 100;
        lLab.Visible := True;
        lLab.Parent := Form1;
      end;
    end;
      

  3.   

    xxmmmx(踢踏) ( ) 信誉:100  2003-04-23 11:06:00  
    DelUser(探索者) ( ) 信誉:100  2003-04-23 11:06:00  
    老兄你的为什么在我前面?
      

  4.   

    呵呵, 在数据库中读取出个数和位置的数据然后就可以了,这样创建 
    procedure TForm1.Button1Click(Sender: TObject);
    var test:Tedit;//个数很多就用数组
    begin
      test:=Tedit.Create(application);
      test.Top:=100;//数据库中读取位置
      test.Left:=100;
      test.Parent:=form1;//告诉他所属的父窗体!
    end;
    其他的东西依次类推!
      

  5.   


        Label1 := TLabel.Create(Self);
        Lable1.Visible := True;
        Lable1.Parent := Form1;
        
        Lable1.Caption:='Lable1';
      

  6.   

    谢谢大家,呵呵,问题解决了,希望能和你们成为朋友
    我的qq:5938099
    msn:[email protected]