Solved

Right Align Edit Boxes

Posted on 2003-11-04
7
514 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 138
drawing animated level bar based on numbers 3 103
Delphi inherited method 6 76
Sending files from  idTcpServer Socket to idTcpClient 2 44
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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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