在可输入的控件里,使敲入的键无效
比如说在Edit 里敲a,s时无效EDIT 里不变
但仍在编辑状态。

解决方案 »

  1.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (Key in ['a','s']) then
        Key := #0
    end;
      

  2.   

    要是在keydown事件里怎么处理?
      

  3.   

    你就是要屏蔽一些键的输入对吧? meiqingsong(阿飛) 的答案是最佳的方法。procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (Key in ['a'..'z','A'..'Z']) then
        Key := #0
    end;以上是屏蔽了a~-z
      

  4.   

    粘贴无效,供参考
      if ((Key = ord('V')) and (ssCtrl in Shift)) then
      begin
        if Clipboard.HasFormat(CF_TEXT) then
          ClipBoard.Clear;
        key := 0;
      end;
      

  5.   

    以上是屏蔽了a-z和A-Z的输入,其他的你可以类似的做一些东西
      

  6.   

    要是在keydown事件里怎么处理?
      

  7.   

    procedure TGetBillFrm.EdtBillBKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      sz:array[0..5] of char;
    begin
      sz[0] := #0;
      if (Key in [Integer('a')..Integer('z'),Integer('A')..Integer('Z')]) then
        // PostMessage(EdtBillB.Handle, WM_SETTEXT, 0, Integer(@sz));
        SetWindowText(EdtBillB.Handle, #0);
        // Key := Integer(#0);
        // Key := 0;
      ShowMessage(IntToStr(Low(Key)) + ' ' + IntToStr(High(Key)) + ' ' + IntToStr(Key));
    end;在OnKeyDown 试了三种方法都不行 中午有空再看看
      

  8.   

    别乱说 OnKeyDown不是同样的处理。
      

  9.   

    土办法。。屏蔽输入框 (Edit)的右键菜单弹出:
       可以拉一空PopMenu,然后使该Edit的PopupMenu属性指向该空PopMenu即可
      

  10.   

    uses  Qt;procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (Key in[key_A..Key_Z,KEY_a..key_z]) then
        Key := 0
    end;
    屏蔽了a-z和A-Z的输入
      

  11.   

    sorry
    上面的还是没效果
      

  12.   

    procedure TForm1.Edit1Change(Sender: TObject);
    var str:string;
        i:integer;
    begin
       str:=edit1.Text;
       for i:=1 to length(str) do
       begin
         if str[i] in ['a','b','m'] then
         begin
           edit1.Text:=copy(str,1,i-1);
           edit1.SelStart:=i;
           exit;
         end;
       end;
    end;
      

  13.   

    这个方法笨是笨了点,但是可以防止CRTl+V