Delphi7如何实现让Tedit显示文字垂直居中(上下居中)
通过下面的组件,可以在输入文字的时候自动垂直居中
直接把下面代码保存到Unit1.pas即可
------------------------------------------
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TEdit = class(StdCtrls.TEdit)
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure KeyPress(var Key: Char); override;
procedure WMSize(var msg: TWMSize);message WM_SIZE;
procedure SetParent(AParent: TWinControl);override;
procedure SetCenter;
end;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Edt: TEdit;
end; var
Form1: TForm1; implementation {$R *.dfm}
{ TEdit } procedure TForm1.FormCreate(Sender: TObject);
begin
Edt := TEdit.Create(self);
Edt.Parent := self;
Edt.AutoSize := False;
Edt.Height := ;
end; procedure TEdit.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or ES_MULTILINE;
end; procedure TEdit.KeyPress(var Key: Char);
begin
inherited;
if Key = # then
key := #;
end; procedure TEdit.WMSize(var msg: TWMSize);
begin
inherited;
SetCenter;
end; procedure TEdit.SetParent(AParent: TWinControl);
begin
inherited;
if Parent <> nil then
begin
SetCenter;
end;
end; procedure TEdit.SetCenter;
var
DC: HDC;
SaveFont: HFont;
Sin: Integer;
SysMetrics, Metrics: TTextMetric;
Rct: TRect;
begin
DC := GetDC();
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(, DC);
if Ctl3D then Sin := else Sin := ;
Rct := ClientRect;
Sin := Height - Metrics.tmHeight - Sin;
Rct.Top := Sin div ;
SendMessage(Handle, EM_SETRECT, , Integer(@Rct));
end; end.
当这个保存成unit1.pas 后,然后通过delphi组件安装功能来安装组件,具体安装方法可以到网上查方法
Delphi7如何实现让Tedit显示文字垂直居中(上下居中)的更多相关文章
- div+css文字垂直居中 解决左侧头像右侧姓名,姓名多换行后相对于头像仍居中显示
在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...
- select中文字垂直居中解决办法
我们知道select标签在各个浏览器中的属性和各浏览器的支持各有些不同,从而造成select选择框在各浏览器的显示有不同,下面我们通过对主要 外形CSS属性的支持,打造全兼容select. 我对sel ...
- 在IE8中使用padding设置select控件文字垂直居中
在火狐.苹果.谷歌.欧鹏等主流浏览器中,select下拉表单的文字能够垂直居中,如图: 而在ie8中,select下拉表单的文字基本就是靠底部显示,如图: 那么,如何使得ie8下的select文字垂直 ...
- [HTML]DIV+CSS 文字垂直居中
在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...
- 文字垂直居中,水平居中 a标签水平居中只要给他的父级设置text-align=center
在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...
- 多行文字垂直居中(完美兼容chrome firefox IE6 7 8 9)
在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...
- 移动Web单行文字垂直居中的问题
单行文字垂直居中的方式你可能可以脱口而出,height和line-height设置为同样就行了,或者设置相同的padding-top和padding-bottom值. 上图是Chrome浏览器下的效果 ...
- css解决文字垂直居中
参考链接: http://www.cnblogs.com/lufy/archive/2012/09/12/2681972.html http://zhidao.baidu.com/question ...
- 00002、div的文字垂直居中与背景的渐变
1.div可以放多行的文字,当显示文字较少时,文字可垂直居中 text-align: center; display: table-cell; vertical-align: middle; text ...
随机推荐
- 解决IDEA因分配内存而引起的卡顿
解决IDEA分配内存不足引起卡顿的问题 在使用IDEA的过程中,经常会运行一段时间后程序卡顿.一段代码可能要敲很久或者出现死机状态,严重影响代码书写速度.经查阅资料,IDEA的自动分配内存最大只有75 ...
- neo4j用collect 代替union 并实行分页
MATCH pa=(j:User)-[r:PostLikeRel|:ReplyRel|:RetweetRel]->(m:User{guid:"f092a1dc6c23b26b020bd ...
- jquery选择器练习
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- WPF LinkButton
<Button Margin="5" Content="Test" Cursor="Hand"> <Button.Temp ...
- MVVM Light Toolkit使用指南
原文:MVVM Light Toolkit使用指南 原文地址: https://blog.csdn.net/ldld1717/article/details/77040077 概述 MVVM Lig ...
- Gitlab+Jenkins学习之路(十四)之自动化脚本部署实践
目录 一.环境说明和准备 1.环境说明 2.服务器准备工作 二.发布脚本编写 1.自动化部署流程设计 2.自动化部署脚本编写 三.发布测试 1.开发机和github添加ssh信任 2.克隆项目到开发机 ...
- Linux每天一个命令:tar
Linux tar命令简介: tar命令可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件.tar最初被用来在磁 ...
- C#对战小游戏,持续更新(里面暂无内容,标记插眼)
做的乱七八糟的 很明显的一点,对集合.数组.类的理解和运用 很差.很差.很差 今儿不做了,马德,头都肿大了 休息一下,捋一捋
- docker 学习笔记(2)--doucker file命令
FROM base ---- imageRUN ---- 执行命令ADD ---- 添加文件COPY ---- 拷贝文件CMD ...
- 微软职位内部推荐-Senior Software Development Engineer_Commerce
微软近期Open的职位: Are you looking for a high impact project that involves processing of billions of dolla ...