[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

Right Align Edit Boxes

Can anyone please help me.  I am having extreme diffuculty with right aligning edit boxes.  

I have an app that uses numbers and it is very frustrating that I can't have my decimal places lined up to the right of an edit box in Delphi.  Very frustrating considering Delphi is such a great language.  You can do it with no problems in VB.  

Can anyone help me and tell me what I need to do?  I am not overly experienced so detailed help would be awesome!  A great answer will mean an increase in points.  Just want to get it done.

Thanks in advance.
Boss.
0
nzboss
Asked:
nzboss
1 Solution
 
kretzschmarCommented:
from barry (inthe):

unit AlignEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;

type
  TEditAlign = class(TEdit)
  private
    { Private declarations }
  f_alignment: TAlignment;
  protected
    { Protected declarations }
    procedure CreateParams(var params:TCreateParams); override;
  procedure SetAlignment(value: TAlignment);
 public
    { Public declarations }
constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
 property Alignment:TAlignment read f_alignment write SetAlignment;
 
  end;

procedure Register;

implementation
constructor TEditAlign.Create(AOwner: TComponent);
begin
  inherited create(AOwner);
  end;

procedure TEditAlign.SetAlignment(value: TAlignment);
begin
  if value<>f_alignment then begin
    f_alignment:=value;
    recreatewnd;
    end;
  end;

procedure TEditAlign.CreateParams(var params:TCreateParams);
const
    Alignments : array[TAlignment] of Longint = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
 inherited CreateParams(Params);
 Params.Style := Params.Style or Alignments[f_Alignment] or ES_MULTILINE;
  end;
procedure Register;
begin
  RegisterComponents('Samples', [TEditAlign]);
end;

end.

meikl ;-)
0
 
geobulCommented:
Hi,

I recommend you to try some of the free components from http://www.torry.net/diffedits.htm
TFloatEdit for example.

Regards, Geo
0
 
nzbossAuthor Commented:
Hi kretzschmar,

How would you go about using this code in an application?

Thanks,
Boss.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kretzschmarCommented:
its a component just install it into delphi-ide-component-palette,
and use it like a TEdit

meikl ;-)
0
 
JackNaifCommented:
The first programme I ever wrote in Delphi was a simple calculator. I run right into this same problem. I suffered on it for a couple of days and then my teacher surprised me with an (unusally) wise answer:

"It doesn't matter what it *is*, but what it *looks like*. Use a TLabel with it's color property set to white, inside a slightly bigger TPanel with it's BevelOuter set to bvLower. Put the numbers in the Caption of the label, and use the alignment property of the label to have it align numbers to the right".

There is still a little bit of a nuisance to this solution: letting the user type or edit the numbers is a bit cumbersome, but it might still be a good solution. It worked for me. =)

Jack
0
 
DreamboatCommented:
Any update here, nzboss?
0
 
nzbossAuthor Commented:
Thanks got on component that works.  Just a shame that Delphi doesn't have this already built in.  CRAZY!

Boss.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now