Solved

Right Align Edit Boxes

Posted on 2003-11-04
7
516 Views
Last Modified: 2010-04-05
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
Comment
Question by:nzboss
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9684589
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
 
LVL 17

Accepted Solution

by:
geobul earned 300 total points
ID: 9685249
Hi,

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

Regards, Geo
0
 

Author Comment

by:nzboss
ID: 9696696
Hi kretzschmar,

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

Thanks,
Boss.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9696718
its a component just install it into delphi-ide-component-palette,
and use it like a TEdit

meikl ;-)
0
 
LVL 1

Expert Comment

by:JackNaif
ID: 9707379
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
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9813555
Any update here, nzboss?
0
 

Author Comment

by:nzboss
ID: 9835291
Thanks got on component that works.  Just a shame that Delphi doesn't have this already built in.  CRAZY!

Boss.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 111
FMX and jaudiotracker playing memory stream 29 98
Firemonkey DbLookupComboBox equivalent ? 2 69
Add New Database Table in database file using delphi 3 34
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question