Solved

vertical centered text in edit box

Posted on 2013-01-29
1
1,385 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 25

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now