Delphi 之 編輯框控制項(TEdit)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   使用   ar   for   

TEdit 組件主要用於資料的輸入和顯示和編輯等操作。

AutoSelect

  擷取組件焦點。該屬性只能在單行文本組件使用。值為True為選中。false則不選中。

BorderStyle

  設定編輯框控制項的外觀效果。當值為bsSingle,為一個單線邊框。為bsNone則無邊框

CanUndo 

  該屬性可以確定使用者修改文本後可以undo方法回退。

CharCase

  設定編輯框控制項文本的大小寫。

 MaxLength 

  設定文本的最大長度,為0表示長度沒有限制。

PasswordChar

  用來顯示字元通常用(*)符號來設定密碼

 ReadOnly

  設定唯讀,不能修改組件的常值內容

SelStart

  設定文本的起始位置,如果為0,則指向第一個文本。

SelLength

  設定文本的最大長度

樣本 選中指定長度的文本

procedure TForm1.Button1Click(Sender: TObject);begin  Edit3.SetFocus;  //擷取焦點  Edit3.SelStart:=StrToInt(Edit1.text); //設定字元的起始位置  Edit3.SelLength:=StrToInt(Edit2.text);//設定字元的個數end;

TEdit組件的事件

OnChange

  編輯框組件被改變時觸發該事件

樣本 驗證文本的合法性

procedure TForm1.Edit1Change(Sender: TObject);var  str:string;begin  str:=‘‘;  str:=Edit1.Text;  if Length(str)>0 then  if not(str[Length(str)]in [‘0‘..‘9‘,#8]) then  begin    Application.MessageBox(‘請輸入數字(‘,‘提示‘,MB_OKCANCEL+MB_ICONINFORMATION);
   Edit1.Text:=LeftStr(Str,Length(Str)-1); end; Edit1.SelStart:=Length(Edit1.text);end;

OnEnter

  組件接受輸入焦點時產生該事件,當視窗組件為啟用狀態時,可使事件處理執行指定的處理。

樣本 組件焦點的設定

procedure TForm1.Edit1Enter(Sender: TObject);begin  if Sender is TEdit then    (Sender as TEdit).Color := $00C8FFFF  else if Sender is TComboBox then    (Sender as TComboBox).Color := $00C8FFFF;end;procedure TForm1.Edit1Exit(Sender: TObject);begin  if Sender is TEdit then    (Sender as TEdit).Color := clWhite  else if Sender is TComboBox then    (Sender as TComboBox).Color := clWhite;end;

OnExit

  當焦點離開時產生的事件

OnKeyPress

  按下鍵盤上的按鍵時產生該事件

樣本 限制輸入的資料

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);begin  if not (Key in [‘a‘..‘z‘,‘A‘..‘Z‘,#8]) then  begin    Application.MessageBox(‘只能輸入英文字元!‘, ‘提示‘, MB_OKCANCEL + MB_ICONINFORMATION);    Key := #0;  end;end;

OnKeyDown

  按下鍵盤上的按鍵觸發該事件,該事件的key是一個整數,是由鍵盤的虛擬索引值而定。

樣本  顯示鍵盤上對應按下的索引值

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  Edit2.Text := IntToStr(Key);  if Shift = [ssShift] then    Edit1.Text := ‘Shift‘  else if Shift = [ssAlt] then    Edit1.Text := ‘Alt‘  else if Shift = [ssCtrl] then    Edit1.Text := ‘Ctrl‘  else    Edit1.Text := ‘‘;end;

 

Delphi 之 編輯框控制項(TEdit)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.