查看: 62|回覆: 0

【Delphi】Utils.StdCtrls

[複製鏈接]

1

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2011-4-10
發表於 2020-12-3 14:41:00 | 顯示全部樓層 |閲讀模式
unit Utils.StdCtrls;

interface

uses
    Classes, Controls, StdCtrls, Windows;

type
    TUiUtil = class(TObject)
    public
        { 控件查找 TWinControl }
        class function GetControlByName(ctrl: TWinControl; const name: string): TControl;
        { 控件查找 TComponent }
        class function GetComponentByName(ctrl: TComponent; const name: string): TComponent;
    end;

////////////////////////////////////////////////////////////////////////////////

    TEditUtil = class(TObject)
    public
        { 内容居中 }
        class function SetTextCenter(text: TEdit): TEdit;
        { 内容居右 }
        class function SetTextRight(text: TEdit): TEdit;
        { 数字框 }
        class function SetTypeNumber(text: TEdit): TEdit;
        { 密码框 }
        class function SetTypePassword(text: TEdit; mask: Char = '*'): TEdit;
        { 强制小写 }
        class function SetLowerCase(text: TEdit): TEdit;
        { 强制大写 }
        class function SetUpperCase(text: TEdit): TEdit;
    end;

implementation

{ 控件查找 TWinControl }
class function TUiUtil.GetControlByName(ctrl: TWinControl; const name: string): TControl;
begin
    Result := ctrl.FindChildControl(name);
end;

{ 控件查找 TComponent }
class function TUiUtil.GetComponentByName(ctrl: TComponent; const name: string): TComponent;
begin
    Result := ctrl.FindComponent(name);
end;


////////////////////////////////////////////////////////////////////////////////

{ 内容居中 }
class function TEditUtil.SetTextCenter(text: TEdit): TEdit;
var
    owner: HWND;
begin
    owner := text.Handle;
    SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_CENTER);
    Result := text;
end;

{ 内容居右 }
class function TEditUtil.SetTextRight(text: TEdit): TEdit;
var
    owner: HWND;
begin
    owner := text.Handle;
    SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_RIGHT);
    Result := text;
end;

{ 数字框 }
class function TEditUtil.SetTypeNumber(text: TEdit): TEdit;
var
    owner: HWND;
begin
    owner := text.Handle;
    SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_NUMBER);
    Result := text;
end;

{ 密码框 }
class function TEditUtil.SetTypePassword(text: TEdit; mask: Char = '*'): TEdit;
var
    owner: HWND;
begin
    if text.PasswordChar = #0 then begin
        text.PasswordChar := mask;
    end;
    owner := text.Handle;
    SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_PASSWORD);
    Result := text;
end;

{ 强制小写 }
class function TEditUtil.SetLowerCase(text: TEdit): TEdit;
var
    owner: HWND;
begin
    owner := text.Handle;
    SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_LOWERCASE);
    Result := text;
end;

{ 强制大写 }
class function TEditUtil.SetUpperCase(text: TEdit): TEdit;
var
    owner: HWND;
begin
    owner := text.Handle;
    SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_UPPERCASE);
    Result := text;
end;

end.




来源:https://www.cnblogs.com/zhuzhongxing/p/14147082.html
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部