各位高手,我處理好了按回車鍵,光標就到下個控件的問題,但問題來了:等到Memo或RichEdit控件時,我想換行,光標卻是跑到下個控件去了,在這個控件上,我怎樣解除掉一按Enter就到下個控件的問題,代替它的是:要同時按下Enter與Shift兩鍵時才能到下個控件?

解决方案 »

  1.   

    同意要同時按下Enter與Shift兩鍵時才能到下個控件
      

  2.   

    但我不知怎樣一當到這個控件時,就取消原來的按Enter,而代替用Enter與Shift同時按下。是不是在這個控件的onKeyPress下寫代碼,怎樣寫呢?
      

  3.   

    你干脆反过来,shift + enter完成换行的功能,enter跳下一个控件。
    这样应该好做点吧!
      

  4.   

    那我怎樣獲得是同時按下shift+enter鍵的信息呢?
      

  5.   

    if (ssshift in  [ssshift]) and (key=13) then
      begin
       showmessage('dasfasf') ;
      end;
      

  6.   

    if not (sender is TMemo) and not (sender is TRichEdit) then selectcontrol()
    selectcontrol 记不清了,就是活动选择控件的那个
      

  7.   

    procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
    begin
    if (ssshift in  [ssshift]) and (key=#13) then
      begin
       showmessage('dasfasf') ;
      end;end;
      

  8.   

    對了,對於shift鍵,不是對應#16嗎?
      

  9.   

    if (ssshift in  [ssshift]) and (key=#13) then
      

  10.   

    用if(key=#13) then 
    begin
      //處理事件阿
    end;
      

  11.   

    還是不行啊!我再描述一下:Form裡有很多控件,當Enter時焦點到下個控件,而遇到TRichEdit或TMemo控件時,則要同時按下Shift+Enter才能使焦點到下個控件。1、我在Form1裡的onKeyPress事件裡這寫也不行:
    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
          if (not (sender is TMemo)) and (not (sender is TRichEdit)) then
             SendMessage(Form1.Handle,WM_NEXTDLGCTL,0,0)
    end;2、同時下面這樣寫也不行:
    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if (Key=#13) then
         SendMessage(Form1.Handle,WM_NEXTDLGCTL,0,0);
    end;procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (ssshift in [ssshift]) and (Key=#13) then
         SendMessage(Form1.Handle,WM_NEXTDLGCTL,0,0)
    end;我要怎樣才可以啊?
      

  12.   

    说个另外的问题哈:对WM_NEXTDLGCTL消息最好用postMessage吧?
      

  13.   

    Do not use the SendMessage function to send a WM_NEXTDLGCTL message if your application will concurrently process other messages that set the focus. Use the PostMessage function instead.
    不知道对你有没有帮助?
      

  14.   

    那有那么麻烦??? keybd_event(VK_TAB, 0, 0, 0);就行了
      

  15.   

    我在Delphi5中试了,就该用PostMessage!
      

  16.   

    keybd_event(VK_TAB, 0, 0, 0);也可以
      

  17.   

    不過我最想的是:怎樣捕捉到同時按下Shift+Enter的信息?
      

  18.   


    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (Key = 13) and not (ssCtrl in Shift)  then
         SendMessage(Self.Handle, WM_NEXTDLGCTL, 0, 0);
    end;
    就用这么一个试试看!
      

  19.   

    在memo或rich中,ctrl + enter是换行!