Solved

vertical centered text in edit box

Posted on 2013-01-29
1
1,461 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
[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
1 Comment
 
LVL 27

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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