TEDIT编辑输入框属性展示
TEDIT编辑框输入框是Delphi最基础的控件之一,这一节我选择这个来展示控制其属性和Delphi桌面程序一样,非常简单易用。
在这个实列中,我选择了13个可见属性进行控制。
可以看出效果还是不错的,基本上VCL能控制的,这里都能控制,一小部分不能控制,不太清楚是否是官方有意为之。
效果图:
实现代码 Unit1.pas
unit Unit1; interface uses System.SysUtils, System.Classes, WEBLib.Graphics, WEBLib.Controls, WEBLib.Forms, WEBLib.Dialogs, WEBLib.ComCtrls, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls, Vcl.ExtCtrls; const TDemoColor: array [0 .. 3] of TColor = (clRed, clGreen, clYellow, clWindow); type TForm1 = class(TWebForm) Panel1: TPanel; WebLabel1: TWebLabel; WebEdit1: TWebEdit; WebButton1: TWebButton; WebButton2: TWebButton; WebButton3: TWebButton; WebButton4: TWebButton; WebButton5: TWebButton; WebButton6: TWebButton; WebButton7: TWebButton; WebButton8: TWebButton; WebButton9: TWebButton; WebButton10: TWebButton; WebButton11: TWebButton; WebButton12: TWebButton; WebButton13: TWebButton; procedure WebButton1Click(Sender: TObject); procedure WebButton2Click(Sender: TObject); procedure WebButton3Click(Sender: TObject); procedure WebButton4Click(Sender: TObject); procedure WebButton5Click(Sender: TObject); procedure WebButton6Click(Sender: TObject); procedure WebButton7Click(Sender: TObject); procedure WebButton8Click(Sender: TObject); procedure WebButton9Click(Sender: TObject); procedure WebButton10Click(Sender: TObject); procedure WebButton11Click(Sender: TObject); procedure WebButton12Click(Sender: TObject); procedure WebEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure WebButton13Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.WebButton10Click(Sender: TObject); begin if WebEdit1.PasswordChar = '*' then WebEdit1.PasswordChar := #0 // 恢复无效 else WebEdit1.PasswordChar := '*'; end; procedure TForm1.WebButton11Click(Sender: TObject); begin WebEdit1.Readonly := not WebEdit1.Readonly; end; procedure TForm1.WebButton12Click(Sender: TObject); var TextDirection: TTextDirection; begin TextDirection := WebEdit1.TextDirection; if high(TTextDirection) = TextDirection then TextDirection := TTextDirection(0) else TextDirection := TTextDirection(integer(TextDirection) + 1); WebEdit1.TextDirection := TextDirection; WebEdit1.Text := WebEdit1.Text; end; procedure TForm1.WebButton13Click(Sender: TObject); begin // WebEdit1.ShowFocus:= not WebEdit1.ShowFocus; WebEdit1.SetFocus; end; procedure TForm1.WebButton1Click(Sender: TObject); begin WebEdit1.Text := WebButton1.Caption; end; procedure TForm1.WebButton2Click(Sender: TObject); var BorderStyle: TBorderStyle; begin BorderStyle := WebEdit1.BorderStyle; if high(TBorderStyle) = BorderStyle then BorderStyle := TBorderStyle(0) else BorderStyle := TBorderStyle(integer(BorderStyle) + 1); WebEdit1.BorderStyle := BorderStyle; end; procedure TForm1.WebButton3Click(Sender: TObject); var Alignment: TAlignment; begin Alignment := WebEdit1.Alignment; if high(TAlignment) = Alignment then Alignment := TAlignment(0) else Alignment := TAlignment(integer(Alignment) + 1); WebEdit1.Alignment := Alignment; end; procedure TForm1.WebButton4Click(Sender: TObject); var Align: TAlign; begin Align := WebEdit1.Align; if high(TAlign) = Align then Align := TAlign(0) else Align := TAlign(integer(Align) + 1); WebEdit1.Align := Align; WebEdit1.Text := IntToStr(Ord(Align)); WebEdit1.Width := 100; WebEdit1.Height := 100; end; procedure TForm1.WebButton5Click(Sender: TObject); var CharCase: TEditCharCase; begin CharCase := WebEdit1.CharCase; if high(TEditCharCase) = CharCase then CharCase := TEditCharCase(0) else CharCase := TEditCharCase(integer(CharCase) + 1); WebEdit1.CharCase := CharCase; end; procedure TForm1.WebButton6Click(Sender: TObject); var i : integer; Color: TColor; function FindPosition(value: TColor): integer; var i : integer; begin result := 0; for i := Low(TDemoColor) to High(TDemoColor) do begin if TDemoColor[i] = value then begin result := i; break; end; end; end; begin Color := WebEdit1.Color; i := FindPosition(Color); if High(TDemoColor) = i then Color := TDemoColor[0] else Color := TDemoColor[i + 1]; WebEdit1.Color := Color; end; procedure TForm1.WebButton7Click(Sender: TObject); var i : integer; Color: TColor; function FindPosition(value: TColor): integer; var i : integer; begin result := 0; for i := Low(TDemoColor) to High(TDemoColor) do begin if TDemoColor[i] = value then begin result := i; break; end; end; end; begin Color := WebEdit1.Font.Color; i := FindPosition(Color); if High(TDemoColor) = i then Color := TDemoColor[0] else Color := TDemoColor[i + 1]; WebEdit1.Font.Color := Color; end; procedure TForm1.WebButton8Click(Sender: TObject); var Size: integer; begin Size := WebEdit1.Font.Size; Size := Size + 2; if Size > 72 then Size := 8; WebEdit1.Font.Size := Size; end; procedure TForm1.WebButton9Click(Sender: TObject); begin WebEdit1.Hint := WebButton9.Caption; WebEdit1.ShowHint := not WebEdit1.ShowHint; end; procedure TForm1.WebEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_RETURN then begin ShowMessage(WebEdit1.Text); end; end; end.
窗体文件Unit1.dfm
object Form1: TForm1 Left = 497 Top = 171 Width = 693 Height = 492 Caption = 'Edit Controls - TForm' Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] TabOrder = 1 object Panel1: TPanel AlignWithMargins = True Left = 30 Top = 30 Width = 633 Height = 432 Margins.Left = 30 Margins.Top = 30 Margins.Right = 30 Margins.Bottom = 30 Align = alClient Caption = 'Standard Component' TabOrder = 0 object WebLabel1: TWebLabel Left = 40 Top = 56 Width = 36 Height = 13 Caption = #32534#36753#26694 Transparent = True end object WebEdit1: TWebEdit Left = 112 Top = 53 Width = 481 Height = 21 AutoCompletion = acURL TabOrder = 0 Text = 'WebEdit1' OnKeyDown = WebEdit1KeyDown end object WebButton1: TWebButton Left = 160 Top = 168 Width = 81 Height = 25 Caption = '1'#12289#36171#20540 TabOrder = 1 OnClick = WebButton1Click end object WebButton2: TWebButton Left = 160 Top = 199 Width = 81 Height = 25 Caption = '2'#12289#36793#26694 TabOrder = 2 OnClick = WebButton2Click end object WebButton3: TWebButton Left = 160 Top = 230 Width = 81 Height = 25 Caption = '3'#12289#23545#40784'['#26080#25928']' TabOrder = 3 OnClick = WebButton3Click end object WebButton4: TWebButton Left = 160 Top = 261 Width = 81 Height = 25 Caption = '4'#12289#25490#21015 TabOrder = 4 OnClick = WebButton4Click end object WebButton5: TWebButton Left = 160 Top = 292 Width = 81 Height = 25 Caption = '5'#12289#22823#23567#20889 TabOrder = 5 OnClick = WebButton5Click end object WebButton6: TWebButton Left = 247 Top = 168 Width = 81 Height = 25 Caption = '6'#12289#32972#26223#39068#33394 TabOrder = 6 OnClick = WebButton6Click end object WebButton7: TWebButton Left = 247 Top = 199 Width = 81 Height = 25 Caption = '7'#12289#23383#20307#39068#33394 TabOrder = 7 OnClick = WebButton7Click end object WebButton8: TWebButton Left = 247 Top = 230 Width = 81 Height = 25 Caption = '8'#12289#23383#21495 TabOrder = 8 OnClick = WebButton8Click end object WebButton9: TWebButton Left = 247 Top = 261 Width = 81 Height = 25 Caption = '9'#12289'Hint'#25552#31034 TabOrder = 9 OnClick = WebButton9Click end object WebButton10: TWebButton Left = 247 Top = 292 Width = 81 Height = 25 Caption = '10'#12289#23494#30721#23383#31526 TabOrder = 10 OnClick = WebButton10Click end object WebButton11: TWebButton Left = 334 Top = 168 Width = 81 Height = 25 Caption = '11'#12289#21482#35835 TabOrder = 11 OnClick = WebButton11Click end object WebButton12: TWebButton Left = 334 Top = 199 Width = 81 Height = 25 Caption = '12'#12289#25991#23383#26041#21521 TabOrder = 12 OnClick = WebButton12Click end object WebButton13: TWebButton Left = 334 Top = 230 Width = 81 Height = 25 Caption = '13'#12289#28966#28857 TabOrder = 13 OnClick = WebButton13Click end end end