Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vertical centered text in edit box

Posted on 2013-01-29
1
Medium Priority
?
1,563 Views
Last Modified: 2013-01-29
Hi,

I am using Delphi 2010.
I have been replacing some panels in my application with Edit boxes to allow user input. It all works well except that the edit boxes will not allow vertical justification. It looks bad on my form and different from the panels which have well centered text.
Is there a version of TEdit that has vertical centering ? Is there an improved TEdit which allows this that I can use or buy ?
0
Comment
Question by:ChLa
1 Comment
 
LVL 28

Accepted Solution

by:
Sinisa Vuk earned 2000 total points
ID: 38833463
There is plenty of edits at: www.torry.net
If you want do it by yourself:
http://www.delphigroups.info/2/4f/85824.html
http://www.scalabium.com/faq/dct0034.htm
http://stackoverflow.com/questions/9758016/how-do-i-custom-draw-of-tedit-control-text
https://forums.embarcadero.com/message.jspa?messageID=426772

...all in all, it is hard task. You can draw text by yourself centered, or you can use tmemo set as single line and center with:

var
  Rect: TRect;
  sz: TSize;
  dc: HDC;
begin
  Memo1.WantReturns := False;
  Memo1.WordWrap := False;
  Memo1.Text := 'sadsadsa'; //put text here
  dc := GetDC(Memo1.Handle);
  GetTextExtentPoint(dc, PansiChar(Memo1.Text), Length(Memo1.Text), sz);
  ReleaseDC(Memo1.Handle, dc);
  SendMessage(Memo1.Handle, EM_GETRECT, 0, LongInt(@Rect));
  Rect.Top := ((Memo1.ClientRect.Bottom-Memo1.ClientRect.Top) - sz.cy) div 2 - 1;
  Rect.Bottom := Rect.Top + sz.cy + 1;
  SendMessage(Memo1.Handle, EM_SETRECT, 0, LongInt(@Rect));
  Memo1.Refresh;

Open in new window


.. for center horizontally ....
edt_style := GetWindowLong(Edit3.Handle, GWL_STYLE);
  SetWindowLong(Edit3.Handle, GWL_STYLE, (edt_style or ES_CENTER));
  SetWindowPos(Edit3.Handle, HWND_TOP, 0, 0, 0, 0,
    SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW);
  Edit3.Refresh;

Open in new window

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

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

824 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