如果你用的是delphi6,就有现成的控件可用,我试过的,不过我现在用的是5,。
祝:身体健康!
祝:身体健康!
解决方案 »
- 欢迎大家进入:从右往左移动曲线,犹如电影字幕!附码了
- dephi 中vf dbf 如何导入?,客户端没有dbf
- 放分200支持 aiirii做大版主——boytomato
- 如何用流保存treeview控件中的StateIndex等属性?
- 请问一个小问题,为什么adocommand在一个工程的两个窗体中不能重名,在线请教??????????????
- 【发布软件兼散分,无需注册,欢迎拷贝,欢迎盗版】
- 一个sql语法的问题!急盼各位高手回音!
- 我刚开始学Delphi,感到与c有太大的区别。以前学c能编不少小程序,但学Delphi却好像没法下手,请问各位有什么好的学习方法?谢谢!
- 请问各位高手,怎样才能过滤IE中的网页。
- 庆祝一下,我的名字在5月份的programer里出现了!!
- 太不象话了,不把程序员当人
- 程序员真的是靠吃青春饭吗?
要控制它们的位置,我觉得做组合控件方面.现在的C#中的UserControl真的是太方便了。 要不给一段代码给你好了!是一个Lable和Memo组合起来的。unit flyMemo;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TflyLabelMemo = class(TCustomControl)
private { Private declarations }
protected
procedure Wmsize(Var Message: TMessage) ; message WM_SIZE ;
procedure CMFontChanged(Var Message :TMessage) ; message CM_FONTCHANGED ;
{ Protected declarations }
public
FTitle :TLabel ;
FTextBox :TMemo ;
constructor Create (AOwner :TComponent); override ;
property Title :TLabel Read FTitle ;
property TextBox :TMemo Read FTextBox ;
//这里定义了,则程序能够使用
{ Public declarations }
published
//如果这里的定义属性,Object Inspector中就会看到
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('flyLib', [TflyLabelMemo]); //注册
end;constructor TflyLabelMemo.Create(Aowner :TComponent) ;
const
Gap =5 ; //label和Memo的间隔
begin
inherited Create(Aowner) ;
Width :=200 ; //设置新控件的高度
Height :=120 ; FTitle :=TLabel.Create(Self) ;
with FTitle do //设置label初始的位置(相对新控件),高度
begin
Parent :=Self ;
Caption :='Title' ;
Left :=Gap ;
Top :=Gap ;
Width :=55 ;
Height :=15 ;
Visible :=True ;
end ; FTextBox :=TMemo.Create(Self) ;
with FTextBox do //设置Memo初始的位置(相对新控件),高度
begin
Parent :=Self ;
Left :=FTitle.Left ;
Top :=FTitle.Top+FTitle.Height+Gap ;
Width :=Self.Width-Left-Gap ;
Visible :=True ;
end ;
end ;procedure TflyLabelMemo.CMFontChanged(Var Message: TMessage) ;
begin //新控件的字体改变了,则需要调整label和Memo的位置
inherited ;
FTextBox.Top :=FTitle.Top+FTitle.Height+5 ;
Height :=FTextBox.Top+FTextBox.Height+5 ;
end ;procedure TflyLabelMemo.Wmsize(Var Message: TMessage) ;
begin // //新控件的大小改变了,则需要调整label和Memo的大小
inherited ;
FTextBox.Width :=Width-(FTextBox.Left+5) ;
FTextBox.Height :=Height-(FTextBox.Top+5) ;
end ;
end.
给你一个LabelEdit的例子,你可以自己扩展他的功能:
unit CLabelEdit;interfaceuses
Windows, Messages, SysUtils, Classes, Controls, Graphics, Forms, Dialogs,
StdCtrls;type
TCLabelEdit = class(TCustomControl)
private
FEdit: TEdit;
FLabel: TLabel;
function GetEditText: string;
function GetLabelText: string;
procedure SetLabelText(const Value: string);
procedure SetEditText(const Value: string);
protected
procedure WMSize(var Message: TMessage); message WM_SIZE;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
public
constructor Create(AOwner: TComponent); override;
published
property EditText: string read GetEditText write SetEditText;
property Font;
property LabelText: string read GetLabelText write SetLabelText;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Samples', [TCLabelEdit]);
end;{ TCLabelEdit }procedure TCLabelEdit.CMFontChanged(var Message: TMessage);
begin
inherited;
FEdit.Top := FLabel.Top + FLabel.Height + 5;
Height := FEdit.Top + FEdit.Height + 5;
end;constructor TCLabelEdit.Create(AOwner: TComponent);
const
Gap = 5;
begin
inherited Create(AOwner);
Width := 200;
Height := 50;
FLabel := TLabel.Create(Self);
FLabel.Parent := Self;
FLabel.Caption := 'Temp';
FLabel.Left := Gap;
FLabel.Top := Gap;
FLabel.Width := 55;
FLabel.Height := 15;
FLabel.Visible := True; FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.Left := FLabel.Left;
FEdit.Top := FLabel.Top + FLabel.Height + Gap;
FEdit.Width := Width - FEdit.Left - Gap;
FEdit.Visible := True;
end;function TCLabelEdit.GetEditText: string;
begin
Result := FEdit.Text;
end;function TCLabelEdit.GetLabelText: string;
begin
Result := FLabel.Caption;
end;procedure TCLabelEdit.SetEditText(const Value: string);
begin
FEdit.Text := Value;
end;procedure TCLabelEdit.SetLabelText(const Value: string);
begin
FLabel.Caption := Value;
end;procedure TCLabelEdit.WMSize(var Message: TMessage);
begin
inherited;
FEdit.Width := Width - (FEdit.Left + 5);
end;end.
请问一下以下代码有什么错?
unit MLabel;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TMLabel = class(TLabel)
private
{ Private declarations }
Edit:TEdit;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create (AOwner: TComponent); override;
published
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TMLabel]);
end;constructor TMLabel.Create (AOwner: TComponent);
begin
inherited Create(Aowner) ;
Edit:=TEdit.Create(self);
Edit.Left:=left+width+3;
edit.Top :=Top;
Edit.Visible:=false;
Edit.Visible:=True;
end;end.
难道一定要从类TCustomControl
继下来吗?
begin
inherited Create(Aowner) ;
Edit:=TEdit.Create(self);
Edit.Left:=left+width+3;
edit.Top :=Top;
end;
为什么程序用这个组件时EDIT显示不出来?