1 unit StdUtils; 2 3 interface 4 5 uses 6 Classes, Controls, StdCtrls, Windows; 7 8 type 9 TUiUtil = class(TObject) 10 public 11 { 控件查找 TWinControl } 12 class function GetControlByName(ctrl: TWinControl; const name: string): TControl; 13 { 控件查找 TComponent } 14 class function GetComponentByName(ctrl: TComponent; const name: string): TComponent; 15 end; 16 17 18 19 TEditUtil = class(TObject) 20 public 21 { 内容居中 } 22 class function SetTextCenter(text: TEdit): TEdit; 23 { 内容居右 } 24 class function SetTextRight(text: TEdit): TEdit; 25 { 数字框 } 26 class function SetTypeNumber(text: TEdit): TEdit; 27 { 密码框 } 28 class function SetTypePassword(text: TEdit; mask: Char = '*'): TEdit; 29 { 强制小写 } 30 class function SetLowerCase(text: TEdit): TEdit; 31 { 强制大写 } 32 class function SetUpperCase(text: TEdit): TEdit; 33 end; 34 35 implementation 36 37 { 控件查找 TWinControl } 38 class function TUiUtil.GetControlByName(ctrl: TWinControl; const name: string): TControl; 39 begin 40 Result := ctrl.FindChildControl(name); 41 end; 42 43 { 控件查找 TComponent } 44 class function TUiUtil.GetComponentByName(ctrl: TComponent; const name: string): TComponent; 45 begin 46 Result := ctrl.FindComponent(name); 47 end; 48 49 50 51 52 { 内容居中 } 53 class function TEditUtil.SetTextCenter(text: TEdit): TEdit; 54 var 55 owner: HWND; 56 begin 57 owner := text.Handle; 58 SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_CENTER); 59 Result := text; 60 end; 61 62 { 内容居右 } 63 class function TEditUtil.SetTextRight(text: TEdit): TEdit; 64 var 65 owner: HWND; 66 begin 67 owner := text.Handle; 68 SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_RIGHT); 69 Result := text; 70 end; 71 72 { 数字框 } 73 class function TEditUtil.SetTypeNumber(text: TEdit): TEdit; 74 var 75 owner: HWND; 76 begin 77 owner := text.Handle; 78 SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_NUMBER); 79 Result := text; 80 end; 81 82 { 密码框 } 83 class function TEditUtil.SetTypePassword(text: TEdit; mask: Char = '*'): TEdit; 84 var 85 owner: HWND; 86 begin 87 if text.PasswordChar = #0 then begin 88 text.PasswordChar := mask; 89 end; 90 owner := text.Handle; 91 SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_PASSWORD); 92 Result := text; 93 end; 94 95 { 强制小写 } 96 class function TEditUtil.SetLowerCase(text: TEdit): TEdit; 97 var 98 owner: HWND; 99 begin 100 owner := text.Handle; 101 SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_LOWERCASE); 102 Result := text; 103 end; 104 105 { 强制大写 } 106 class function TEditUtil.SetUpperCase(text: TEdit): TEdit; 107 var 108 owner: HWND; 109 begin 110 owner := text.Handle; 111 SetWindowLong(owner, GWL_STYLE, GetWindowLong(owner, GWL_STYLE) or ES_UPPERCASE); 112 Result := text; 113 end; 114 115 end.
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!