Solved

vertical centered text in edit box

Posted on 2013-01-29
1
1,425 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 26

Accepted Solution

by:
Sinisa Vuk earned 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

776 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