Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vertical centered text in edit box

Posted on 2013-01-29
1
Medium Priority
?
1,528 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

670 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