Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Alignment in Edit fields

Posted on 1998-08-18
10
Medium Priority
?
176 Views
Last Modified: 2010-04-04
How do I right allign numeric data in a Tedit field?
0
Comment
Question by:mvsatis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 1

Expert Comment

by:Greedy
ID: 1337214
I can give you a component called a TCurrencyEdit it has an Alignment property (right, center, left) it also has decimal places and DisplayFormat so you can put in things like $, lbs, ect...it is from the Rx Libraries, you can download them free at
http://www.rx.demo.ru
http://www.kki.net.pl/rxlib/


0
 
LVL 8

Accepted Solution

by:
ZifNab earned 300 total points
ID: 1337215
Hi mvsatis,

Here is the answer (from delphi Corner) to your question, but not one you like I suppose :


----------

TEdit and right-justification of text
How can I get a TEdit to display right-justified text?

There is no way to do this at runtime because there's no facility in TEdit to right-align text. The reason is simple: In order to have right-aligned text in Windows, you have to support multiple lines! Well, an Edit control with multiple lines is really a TMemo. So you can use a TMemo to simulate a single line TEdit, without the hassle of building your own component.

There are a few things you should be aware of if you do this, though.

You need to set WantReturns and WordWrap properties to False to ensure that you don't have text wrapping and that lines don't disappear when the user presses Enter.
Limit the number of characters that can be entered into the TMemo with the MaxLength property.
To prevent the user from inadvertently making text go away with the down arrow (assuming you've added some text to the TMemo), in the OnCreate of the form, set the SelStart property to the Length of the TMemo's text:
Memo1.SelStart := Length(Memo1.Text);
Trap for key-presses to prevent the user from using Ctrl-Enter and Ctrl-Tab, which are hard returns and hard tabs, respectively. To trap for Ctrl-Enter, write the following in the OnKeyPress event of the TMemo:
procedure TForm1.Memo1KeyPress(Sender : TObject; var Key : Char);
begin
  if Key = #10 then //Ctrl-Enter?
    Key := #0; //Kill it
end;
To trap for Ctrl-Tab, do the following in the OnKeyDown:

procedure TForm1.Memo1KeyDown(Sender : TObject; var Key : Word; Shift :
TShiftState);
begin
  if (Key = VK_TAB) AND (ssCtrl in Shift) then
    Key := 0;
end;
The reason for using both OnKeyPress and OnKeyDown is that in the first instance, I didn't need to trap a Shift state, but in the second I did need to.

This seems like a lot, but actually it's a far simpler than creating a new TEdit that will support right-justification of text. In the case of the TEdit descendant, you'd have to override the Paint method and add an alignment property that calls the Paint method when its value is changed. Sounds simple enough, but component writing is never trivial.

Copyright © 1995, 1996, 1997 Brendan V. Delumpa All Rights Reserved

--------------

So, using a TEdit won't get you to what you want. So what can you do? 1. Use a TMemo, like above OR 2. make an own component OR 3. Use an already made component! And there are already a lot of them on the web. One I usually use is the one of RLib, because I like this freeware library a lot (see Matvey's comment).

Regards, Zif.

PS. Matvey, hope you don't mind I've answered this one. But I did this, because it's right on to the question.


0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337216
Hi,
On DSP there is a fw component that might do it. Haven't tested it myself, so...
http://sunsite.icm.edu.pl/delphi/ftp/d10free/gestedit.zip

/// John
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.

 
LVL 4

Expert Comment

by:erajoj
ID: 1337217
NOW I have tested it, and it seems to work very well...?!?!

/// John
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337218
...It is actually a simple solution to some other of my needs...
.especially valid char masking.
Thank you David Robledo Fernández!

/// John
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1337219
Simplest way:

Subclass the TEdit component
Override the createParam method
In your createParam method, set the ParamStyle

Let me know if you need code.


0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337220
kjteng, that's indeed a simple way, make another component. But then again, why not using one which already exist?

Ok, but we all agree that it isn't possible to do with the native TEdit... except is is somewhat possible with the native TMemo.

Zif.
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1337221
Zif:
Sorry I didn't see your answer when I post the comment - something wrong with my browser.

Why not using one which already exist?
IMHO,
If ( what we want is just a simple task such as aligning text)
  and (we do not need the extra features provided by the third   party component) then
it is better to write our own component as this will minimise the overheads.

By the way where is Matvey's comment? I can see it in the browser.



0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337222
mmm, yes strange this happen here, where is Matvey's comment.
kjteng, write, if it is for simple extension, new component is better.
0
 

Author Comment

by:mvsatis
ID: 1337223
OK I have tested your solution and it works,but it is a little bit teddious.
Now I have found on the net several components who will tho this job more easaly.

Look to www.torry.ru (excellent site) or DSP.


           
0

Featured Post

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.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

719 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