思考半年都未解决的问题(奉献全部积分)(200分)

  • 主题发起人 主题发起人 scLizongliang
  • 开始时间 开始时间
S

scLizongliang

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在以TQRDBTEXT作父类做一控件,可TQRDBtext(TDBtext,Tlabel,TQrlablel)没有象
Tedit类类似的OnChange事件,怎么加入?
加入的代码(大致)如下(实现无级缩放,代码可能有错):
var
lf:TLogFont;
tf:TFont;
begin
tf:=TFont.Create;
tf.Assign(Font);
GetObject(tf.Handle,sizeof(lf),@lf);
lf.lfHeight:=(TQRDBTEXT.Height-2);
lf.lfWidth:=TQRDBTEXT.Width div (length(trim(TQRDBTEXT.caption))+2);
end;
tf.Handle:=CreateFontIndirect(lf);
Font.Assign(tf);
tf.Free;
end;
由于逻辑字体宽度(lf.lfWidth)只能为整数,字多并不能缩放满,望高手看看、解决,自做控件原码如下:




unit AutoFontEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls,Graphics;
type
TAutoFontEdit=class(TEdit)
private
{ Private declarations }
FAutoSize:boolean;
//procedure Startinit(Sender:TObject);
protected
{ Protected declarations }
procedure ChangeText(Sender:TObject);
procedure ExitText(Sender:TObject);
procedure EnterText(Sender:TObject);
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor destroy;override;
published
{ Published declarations }
property Font;
property Height;
property Width;
Property AutoSize;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('lzl', [TAutoFontEdit]);
end;

constructor TAutoFontEdit.Create(AOwner: TComponent);
begin
FAutoSize:=False;
inherited;
OnChange:=ChangeText;
OnExit:=ExitText;
OnEnter:=EnterText;
AutoSize:=False;
Font.Name:='宋体';
//Startinit(AOwner as TEdit);
end;

destructor TAutoFontEdit.destroy;
begin
inherited;
end;

procedure TAutoFontEdit.ChangeText(Sender:TObject);
var
lf:TLogFont;
tf:TFont;
begin
tf:=TFont.Create;
tf.Assign(Font);
GetObject(tf.Handle,sizeof(lf),@lf);
lf.lfHeight:=(Height-2);
if length(text)>0 then begin
lf.lfWidth:=Width div (length(trim(text))+2);
end;
tf.Handle:=CreateFontIndirect(lf);
Font.Assign(tf);
tf.Free;
end;


procedure TAutoFontEdit.ExitText(Sender:TObject);
var
lf:TLogFont;
tf:TFont;
begin
tf:=TFont.Create;
tf.Assign(Font);
GetObject(tf.Handle,sizeof(lf),@lf);
lf.lfHeight:=(Height-2);
if length(text)>0 then begin
lf.lfWidth:=Width div length(trim(text));
end;
tf.Handle:=CreateFontIndirect(lf);
Font.Assign(tf);
tf.Free;
end;


procedure TAutoFontEdit.EnterText(Sender:TObject);
var
lf:TLogFont;
tf:TFont;
begin
tf:=TFont.Create;
tf.Assign(Font);
GetObject(tf.Handle,sizeof(lf),@lf);
lf.lfHeight:=(Height-2);
if length(text)>0 then begin
lf.lfWidth:=Width div (length(trim(text))+2);
end;
tf.Handle:=CreateFontIndirect(lf);
Font.Assign(tf);
tf.Free;
end;

{
procedure TAutoFontEdit.Startinit(Sender:TObject);
var
lf:TLogFont;
tf:TFont;
begin
tf:=TFont.Create;
tf.Assign(Font);
GetObject(tf.Handle,sizeof(lf),@lf);
lf.lfHeight:=(Height-2);
if length(text)>0 then begin
lf.lfWidth:=Width div length(trim(text));
end;
tf.Handle:=CreateFontIndirect(lf);
Font.Assign(tf);
tf.Free;
end;
}


end.






 
半年了未解决就算了吧,
我认为解决方法很多,
不要一味的想一个问题!
 
to libaoliang:怎么没解决就算了呢?!我还要用—,能详细说说你的一种能解决的方法吗?
小弟不胜感激,小弟在网吧上DFW,好不容易…………
 
解决了不要忘了告诉我一声,我是也遇到这个问题,就是报表中的Text中的文字不定。
 
各位富翁,哪儿有UML入门的电子书(.pdf)下载
 
to:true_afei我有,不过...
嘿嘿...银子吗
 
四川李忠良
 
用别的报表控件如何?
 
to wlmmlw:我想QuickRep应该是可以解决的,目前我还没有用过其它(for d6)报表过。
 
不但没有Onchang 而且没有 onMouseDown OnMouseMove OnMouseUp
不知该怎样加,我也困扰了很久.
 
鼠标事件原来就有,可以公开鼠标事件
捕捉CM_TEXTCHANGED可以增加OnChange事件
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,QuickRpt, QRCtrls;

type
TQE = class(TQRDBText)
private
{ Private declarations }
FOnChange:TNotifyEvent;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
protected

public
{ Public declarations }
published
property Text;
//公开鼠标事件
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
//改变事件
property OnChange:TNotifyEvent read FOnChange write FOnChange;
end;

implementation


{ TQE }

procedure TQE.CMTextChanged(var Message: TMessage);
begin
inherited;
if Assigned(FOnchange) then
FOnChange(Self);
end;



end.

 
to scLizongliang:
我是綿陽的,你的lizongliang@china.com.cn發不過去。我的chinakama@hotmail.com
請聯系.
 
to wr960204:谢谢你的解答。我回家试试……
 
后退
顶部