zoukankan      html  css  js  c++  java
  • 【Delphi】Utils.StdCtrls

    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.
    
    
    
  • 相关阅读:
    蛋疼的时候写三消游戏(十一) 圆形时钟
    C# 中的volatile关键字 (我今天才知道)
    第十四周助教总结
    第十周助教总结
    第十二周助教总结
    C语言I博客作业04
    C语言I博客作业05
    C语言I博客作业02
    第十一周助教总结
    第十三周助教总结
  • 原文地址:https://www.cnblogs.com/zhuzhongxing/p/14147082.html
Copyright © 2011-2022 走看看