close
{讓Edit只接受數字} 

{方法1}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin 
  if  not (Key in [ '0'  .. '9' ]) then
    Key := Chr( 0 );
end ;

{方法2} 
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin 
  if  not (Byte(Key) in [ 48 .. 57 ]) then   // 0的Ascii是48
    Key := Chr( 0 );
end ;

{方法3}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin 
  if  not CharInSet(Key, [ '1' .. '5' ]) then Key : = #0 ;
end ;

{Edit文本的選擇與由游標位置} 
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.SetFocus;                           
  SendMessage(Edit1.Handle,EM_SETSEL, 0 , 1 );  //選擇第一個字符
  SendMessage(Edit1.Handle,EM_SETSEL, 0 ,- 1 ); //全選
  SendMessage(Edit1.Handle,EM_SETSEL, 1 , 1 );  //光標移到第一個字符後面
  SendMessage(Edit1.Handle,EM_SETSEL, 0 , 0 ) ; //光標移到開始
  SendMessage(Edit1.Handle,EM_SETSEL,- 1 , 0 ); //光標移到開始 
end ;


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 KevinYoung 的頭像
    KevinYoung

    KevinYoung

    KevinYoung 發表在 痞客邦 留言(0) 人氣()