我怎么控制memo控件每行只可以输入规定的字符数呢?

解决方案 »

  1.   

    var
      Form1: TForm1;
      Lpos,Cpos,Linelength:integer; //Lpos返回行的位置,Cpos返回字符位置,LineLength返回选中的长度implementation{$R *.dfm}procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      Lpos:=SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0);
      Cpos:=SendMessage(Memo1.Handle,EM_LINEINDEX,Lpos,0);
      LineLength:=SendMessage(Memo1.Handle,EM_LINELENGTH,Cpos,0);
      Cpos:=Memo1.SelStart-Cpos;
      if Cpos>=9 then    //如果 规定10个字符
         keybd_event( VK_RETURN, MapVirtualKey( VK_RETURN, 0 ), 0 , 0 );
    end;