为什么CHSHENGT等三个COMBOBOX的控件无法显示?(100分)

  • 主题发起人 主题发起人 南腔北调
  • 开始时间 开始时间

南腔北调

Unregistered / Unconfirmed
GUEST, unregistred user!
unit GroupBox1;

interface

uses
SysUtils, Classes, Controls, StdCtrls,ComboBoxEnter;

type
TGroupBox1 = class(TGroupBox)
chaddlab1:tlabel;
chaddlab2:tlabel;
chaddlab3:tlabel;
chsheng:TComboBoxEnter;
chcity:TComboBoxEnter;
chcityzone:TComboBoxEnter;
private

{ Private declarations }
protected
{ Protected declarations }
public
constructor Create (AOwner:TComponent);override;
procedure CreateWnd;override;
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('CHGroupware', [TGroupBox1]);
end;

{ TGroupBox1 }

constructor TGroupBox1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if Assigned(chaddlab1) then exit;
chaddlab1:=tlabel.Create(AOwner);
chaddlab1.Parent:=self;
chaddlab1.FocusControl:=self;
chaddlab1.Top:=24;
chaddlab1.Left:=16;
chaddlab1.Name:='chaddlab1';
chaddlab1.Caption:='省份:';

chaddlab2:=tlabel.Create(AOwner);
chaddlab2.Parent:=self;
chaddlab2.FocusControl:=self;
chaddlab2.Top:=49;
chaddlab2.Left:=16;
chaddlab2.Name:='chaddlab2';
chaddlab2.Caption:='城市:';

chaddlab3:=tlabel.Create(AOwner);
chaddlab3.Parent:=self;
chaddlab3.FocusControl:=self;
chaddlab3.Top:=73;
chaddlab3.Left:=16;
chaddlab3.Name:='chaddlab3';
chaddlab3.Caption:='城区:';

chsheng:=TComboBoxEnter.Create(AOwner);
chsheng.Parent:=self;
chsheng.Name:='chsheng';
chsheng.Style:=csDropDownList;
chsheng.Top:=21;
chsheng.Left:=51;
chsheng.Width:=105;

chcity:=TComboBoxEnter.Create(AOwner);
chcity.Parent:=self;
chcity.Name:='chcity';
chcity.Style:=csDropDownList;
chcity.Top:=45;
chcity.Left:=51;
chcity.Width:=105;

chcityzone:=TComboBoxEnter.Create(AOwner);
chcityzone.Parent:=self;
chcityzone.Name:='chcityzone';
chcityzone.Style:=csDropDownList;
chcityzone.Top:=69;
chcityzone.Left:=51;
chcityzone.Width:=105;

end;

procedure TGroupBox1.CreateWnd;
begin
inherited;

end;

end.


但是label均可显示出来。。。求各位指点一下。。。
 
chsheng.Parent:=AOwner;
 
呵呵!在这真能学好多东西!!
 
to mstar
那样设置的话
chsheng就在FORM上了,不是在这个容器(TGroupBox1)内
不信可以试试
 
我改了 一点问题没有 你看
unit GroupBox1;

interface

uses
SysUtils, Classes, Controls, StdCtrls;

type
TGroupBox1 = class(TGroupBox)
chaddlab1:tlabel;
chaddlab2:tlabel;
chaddlab3:tlabel;
chsheng:TComboBox;
chcity:TComboBox;
chcityzone:TComboBox;
private

{ Private declarations }
protected
{ Protected declarations }
public
constructor Create (AOwner:TComponent);override;
procedure CreateWnd;override;
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('MSTAR', [TGroupBox1]);
end;

{ TGroupBox1 }

constructor TGroupBox1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if Assigned(chaddlab1) then exit;
chaddlab1:=tlabel.Create(AOwner);
chaddlab1.Parent:=self;
chaddlab1.FocusControl:=self;
chaddlab1.Top:=24;
chaddlab1.Left:=16;
chaddlab1.Name:='chaddlab1';
chaddlab1.Caption:='省份:';

chaddlab2:=tlabel.Create(AOwner);
chaddlab2.Parent:=self;
chaddlab2.FocusControl:=self;
chaddlab2.Top:=49;
chaddlab2.Left:=16;
chaddlab2.Name:='chaddlab2';
chaddlab2.Caption:='城市:';

chaddlab3:=tlabel.Create(AOwner);
chaddlab3.Parent:=self;
chaddlab3.FocusControl:=self;
chaddlab3.Top:=73;
chaddlab3.Left:=16;
chaddlab3.Name:='chaddlab3';
chaddlab3.Caption:='城区:';

chsheng:=TComboBox.Create(AOwner);
chsheng.Parent:=self;
chsheng.Name:='chsheng';
chsheng.Style:=csDropDownList;
chsheng.Top:=21;
chsheng.Left:=51;
chsheng.Width:=105;

chcity:=TComboBox.Create(AOwner);
chcity.Parent:=self;
chcity.Name:='chcity';
chcity.Style:=csDropDownList;
chcity.Top:=45;
chcity.Left:=51;
chcity.Width:=105;

chcityzone:=TComboBox.Create(AOwner);
chcityzone.Parent:=self;
chcityzone.Name:='chcityzone';
chcityzone.Style:=csDropDownList;
chcityzone.Top:=69;
chcityzone.Left:=51;
chcityzone.Width:=105;

end;

procedure TGroupBox1.CreateWnd;
begin
inherited;

end;
end.
 
呵呵,你写的也是:
chsheng.Parent:=self;
而不是你说的:
chsheng.Parent:=AOwner;

不过我发现这段代码没有问题,是我的那个COMBOBOXENTER有问题,各位再帮我看看吧:
unit ComboBoxEnter;

interface

uses
SysUtils, Classes, Controls, StdCtrls,Forms,messages;

type
TComboBoxEnter = class(TComboBox)
private
{ Private declarations }
protected
{ Protected declarations }
public
procedure CreateWnd;override;
procedure EnterPress(Sender: TObject; var Key: Char);
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('CHGroupware', [TComboBoxEnter]);
end;

{ TComboBoxEnter }
procedure TComboBoxEnter.CreateWnd;
begin
inherited;
Ctl3D:=false;
BevelKind:=bkflat;
onKeyPress:=EnterPress;
end;

procedure TComboBoxEnter.EnterPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
key:=#0;
(self.Owner as tform).perform(WM_NEXTDLGCTL,0,0);
end;
end;

end.
 
控件的 CREATE 都应该这样
constructor Create(AOwner: TComponent); override;
 
label是autowidth的,所以height width会根据文字实际占用大小进行调整
而其他控件就不会,所以width=0 height=0 当然看不到了。
 
多人接受答案了。
 

Similar threads

后退
顶部