如题:
    怎么用MaskEdit实现限制用户只能输入某几个字母?
    比如首字母只能输入A和B,输入其他字母则错误。

解决方案 »

  1.   

    响应OnKeyPress事件:
      if TMaskEdit(Sender).SelStart = 0 then
        if not (Key in ['A','B']) then
        begin
          Beep;
          Key := #0
        end
      

  2.   

    editmask属性里指定匹配条件
      

  3.   

    OnKeyPress或OnKeyDown最适合
      

  4.   

    MaskEdit1KeyPressif Length(MaskEdit1.Text)=0 then
      begin
        if not (key in ['A','B','a','b']) then
        begin
          key:=#0;
        end;
      end;