Delphi7 How to enable Tedit display text to center vertically (up and down center)

Source: Internet
Author: User

With the following components, you can automatically center vertically when you enter text
Save the following code directly to Unit1.pas
------------------------------------------

UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;typeTedit=class(Stdctrls.tedit)protected    procedureCreateParams (varParams:tcreateparams);Override; procedureKeyPress (varKey:char);Override; procedureWmsize (varMsg:twmsize);messagewm_size; procedureSetParent (Aparent:twincontrol);Override; procedureSetCenter; End; TForm1=class(tform) Button1:tbutton;    Edit1:tedit; procedureformcreate (Sender:tobject); Private    {Private Declarations}   Public    {Public Declarations}Edt:tedit; End;varForm1:tform1;Implementation{$R *.DFM}{Tedit}proceduretform1.formcreate (sender:tobject);beginEdt:= Tedit.Create(self); Edt.parent:=Self ; Edt.autosize:=False; Edt.height:= -;End;procedureTedit.createparams (varparams:tcreateparams);begin  inherited; Params.style:= Params.styleorEs_multiline;End;procedureTedit.keypress (varKey:char);begin  inherited; ifKey = # -  ThenKey:= #0;End;procedureTedit.wmsize (varmsg:twmsize);begin  inherited; SetCenter;End;proceduretedit.setparent (Aparent:twincontrol);begin  inherited; ifParent <>Nil  Then  beginSetCenter; End;End;procedureTedit.setcenter;varDc:hdc; Savefont:hfont; Sin:integer; SysMetrics, Metrics:ttextmetric; Rct:trect;beginDC:= GetDC (0); GetTextMetrics (DC, SysMetrics); Savefont:=SelectObject (DC, Font.handle); GetTextMetrics (DC, Metrics); SelectObject (DC, Savefont); ReleaseDC (0, DC);ifCtl3d ThenSin: =8 ElseSin: =6; RCT:=Clientrect; Sin:= Height-metrics.tmheight-Sin; Rct.top:= SinDiv 2; SendMessage (Handle, Em_setrect,0, Integer (@Rct));End;End.

When this is saved to Unit1.pas, and then through the Delphi Component installation function to install the components, the specific installation method can go to the online search method

Delphi7 How to enable Tedit display text to center vertically (up and down center)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.