 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jim Davis Guest
|
Posted: Wed Nov 05, 2003 1:51 am Post subject: Desired TAlignedEdit feature |
|
|
There are lots of examples of Tedit descendants that add an
Alignment property to TEdit like this code from Peter Below:
unit AlignedEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;
type
TAlignedEdit = class(TEdit)
private
fAlignment: TAlignment;
procedure SetAlignment(const Value: TAlignment);
{ Private declarations }
protected
{ Protected declarations }
Procedure CreateParams( Var params: TCreateParams ); override;
public
{ Public declarations }
published
{ Published declarations }
property Alignment: TAlignment read fAlignment write
SetAlignment
default taLeftJustify;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PBGoodies', [TAlignedEdit]);
end;
{ TAlignedEdit }
procedure TAlignedEdit.CreateParams(var params: TCreateParams);
const
Styles : Array [TAlignment] of DWORD =
(ES_LEFT, ES_RIGHT, ES_CENTER );
begin
inherited;
params.style := params.style or Styles[ Falignment ];
end;
procedure TAlignedEdit.SetAlignment(const Value: TAlignment);
begin
If fAlignment <> Value Then Begin
fAlignment := Value;
RecreateWnd;
End;
end;
end.
This component works great except for one drawback. It won't right
justify if you assign text to it longer than the control at run
time. In other words, the code:
MyAlignedEdit.Text := '1234567.890';
will overflow the control to the right with the text left aligned
even though the control's Alignment property is set to
taRightJustify. If there is only room for 6 characters it shows
'123456'. What I want is for the text to be right aligned with the
text overflowing to the left, just as a TLabel would with the
following code:
MyLabel.Caption := '1234567.890';
showing '67.890'.
I've looked at a number of controls but none exhibit the desired
behavior.
Can anyone suggest modifications to Peter's code above, a third
party freeware component, or a convenient workaround? A Tedit with
a Canvas property perhaps?
Thanks,
Jim Davis
|
|
| Back to top |
|
 |
Yorai Aminov (TeamB) Guest
|
Posted: Wed Nov 05, 2003 8:57 am Post subject: Re: Desired TAlignedEdit feature |
|
|
On 4 Nov 2003 18:51:23 -0700, Jim Davis <jimdavis2 (AT) earthlink (DOT) net>
wrote:
| Quote: | This component works great except for one drawback. It won't right
justify if you assign text to it longer than the control at run
time.
|
That's because the edit control tries to show as much text as
possible, based on the current selection. Try setting the SelStart
property to position the cursor at the end of the text.
---
Yorai Aminov (TeamB)
http://develop.shorterpath.com/yorai
(TeamB cannot answer questions received via email.)
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|