请参考procedure TyyMAC.MACKeyPress(Sender: TObject; var Key: Char); var N: Integer ; begin //让编辑框只能输入数字和'A'..'F' case Ord(Key) of Ord('0')..Ord('9'), Ord('A')..Ord('F'): ; //normal Ord('a')..Ord('f'): Dec(Key, 32) ; //UpperCase VK_BACK: begin if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then begin Key := #0 ; N := (Sender as TEdit).Tag ; case N of 2, 3, 4, 5, 6: begin FEditMAC[N - 1].SetFocus ; FEditMAC[N - 1].SelStart := Length(FEditMAC[N - 1].Text) ; FEditMAC[N - 1].SelLength:= 0 ; end ; else ; end ; //of case end ; //of if end ; Ord('-'): begin //next subip or mask Key := #0 ; N := (Sender as TEdit).Tag ; case N of 1, 2, 3, 4, 5: FEditMAC[N + 1].SetFocus ; end ; //of case end ; else Key := #0 ; end ; //of case end;procedure TyyMAC.MACKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var N: Integer ; begin //处理上下左右键,KeyPress事件不支持 case Key of VK_LEFT, VK_UP : begin if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then begin N := (Sender as TEdit).Tag ; case N of 2, 3, 4, 5, 6: begin FEditMAC[N - 1].SetFocus ; FEditMAC[N - 1].SelStart := Length(FEditMAC[N - 1].Text) ; FEditMAC[N - 1].SelLength:= 0 ; end ; else ; end ; //of case end ; //of if end ; VK_RIGHT, VK_DOWN : begin if ((Sender as TEdit).SelStart = Length((Sender as TEdit).Text)) and ((Sender as TEdit).SelLength= 0) then begin N := (Sender as TEdit).Tag ; case N of 1, 2, 3, 4, 5: begin FEditMAC[N + 1].SetFocus ; FEditMAC[N + 1].SelStart := 0 ; FEditMAC[N + 1].SelLength:= 0 ; end ; end ; //of case end ; //of if end ; end ; //of case end;
var N: Integer ;
begin
//让编辑框只能输入数字和'A'..'F'
case Ord(Key) of
Ord('0')..Ord('9'), Ord('A')..Ord('F'): ; //normal
Ord('a')..Ord('f'): Dec(Key, 32) ; //UpperCase
VK_BACK: begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
Key := #0 ;
N := (Sender as TEdit).Tag ;
case N of
2, 3, 4, 5, 6:
begin
FEditMAC[N - 1].SetFocus ;
FEditMAC[N - 1].SelStart := Length(FEditMAC[N - 1].Text) ;
FEditMAC[N - 1].SelLength:= 0 ;
end ;
else ;
end ; //of case
end ; //of if
end ;
Ord('-'): begin //next subip or mask
Key := #0 ;
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3, 4, 5: FEditMAC[N + 1].SetFocus ;
end ; //of case
end ;
else Key := #0 ;
end ; //of case
end;procedure TyyMAC.MACKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var N: Integer ;
begin
//处理上下左右键,KeyPress事件不支持
case Key of
VK_LEFT,
VK_UP : begin
if ((Sender as TEdit).SelStart = 0) and ((Sender as TEdit).SelLength = 0) then
begin
N := (Sender as TEdit).Tag ;
case N of
2, 3, 4, 5, 6:
begin
FEditMAC[N - 1].SetFocus ;
FEditMAC[N - 1].SelStart := Length(FEditMAC[N - 1].Text) ;
FEditMAC[N - 1].SelLength:= 0 ;
end ;
else ;
end ; //of case
end ; //of if
end ;
VK_RIGHT,
VK_DOWN : begin
if ((Sender as TEdit).SelStart = Length((Sender as TEdit).Text)) and
((Sender as TEdit).SelLength= 0) then
begin
N := (Sender as TEdit).Tag ;
case N of
1, 2, 3, 4, 5:
begin
FEditMAC[N + 1].SetFocus ;
FEditMAC[N + 1].SelStart := 0 ;
FEditMAC[N + 1].SelLength:= 0 ;
end ;
end ; //of case
end ; //of if
end ;
end ; //of case
end;