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.
    
    
    
  • 相关阅读:
    627. Swap Salary
    176. Second Highest Salary
    596. Classes More Than 5 Students
    183. Customers Who Never Order
    181. Employees Earning More Than Their Managers
    182. Duplicate Emails
    175. Combine Two Tables
    620. Not Boring Movies
    595. Big Countries
    HDU 6034 Balala Power! (贪心+坑题)
  • 原文地址:https://www.cnblogs.com/zhuzhongxing/p/14147082.html
Copyright © 2011-2022 走看看