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.
    
    
    
  • 相关阅读:
    模式识别 第一章 概论
    高等代数9 欧几里得空间
    离散数学6 初等数论
    高等代数6 线性空间
    高等代数5 二次型
    GMOJ 6870. 【2020.11.17提高组模拟】ckw的树 (tree)
    1
    Virtual Tree 学习笔记
    [2020.11.14提高组模拟] 鬼渊传说(village)
    企业购置新车,各项费用会计入账以及案例分析
  • 原文地址:https://www.cnblogs.com/zhuzhongxing/p/14147082.html
Copyright © 2011-2022 走看看