procedure TfrmMain.CreateTabSheet( myFormClass: TFormClass;var Reference: TForm); 
var 
MyForm : TForm; 
begin 
tabsheet := TRzTabSheet.Create(RpgcMain); 
try 
tabsheet.Caption := Reference.Caption; 
tabsheet.PageControl := RpgcMain; 
tabsheet.Name := stabsheetname; 
MyForm := myFormClass.Create(tabsheet); 
try 
MyForm.Parent := tabsheet; 
MyForm.BorderStyle := bsnone; 
MyForm.WindowState := wsmaximized; 
RpgcMain.ActivePage := tabsheet; 
MyForm.Show; 
except 
FreeAndNil(MyForm); 
end; 
except 
FreeAndNil(tabsheet); 
end; 
end; 把窗体放入PageControl后,如何处理PageControl中Form内的KeyDown事件

解决方案 »

  1.   

    PageControl中Form内同时有FormKeyPress和KeyDown事件
      

  2.   

    但主窗体内没有FormKeyPress和KeyDown事件
      

  3.   

    預想中,你的keydown事件應該怎么被觸發的?
    可以舉個例子說明一下預想的過程,再說明一下實際碰到的狀況。這樣人家才知道問題所在
      

  4.   

    //FormKeyPress
    if key = #13 then begin
      if IsTEdit then
        begin
          Key:= #0;
          Perform(WM_NEXTDLGCTL,0,0);
        end
    end;//FormKeyDown
    if key=VK_F7  then  
    begin
       key:=0;      
       edit1.SetFocus;
    end
    else if key=VK_F8  then   
    begin
       key:=0;      
       edit2.SetFocus;
    end
    else if key=VK_F9  then   
    begin
       key:=0;      
       edit4.SetFocus;
    end;
      

  5.   

    PageControl中Form内同时有FormKeyPress和KeyDown事件
    FormKeyPress\FormKeyDown都不响应
      

  6.   

    在 PageControl 所在的 Form 的 OnKeyPress 中处理。
      

  7.   

    1、keypress是不能收到如回車(#13)這類按鍵訊息的,只有在keydown可以收到;
    2、看你的程式,我猜測你的目的:你的form.keypreview為True,來控制UI上的focus
      所以問題點在,當你keydown時,消息預先發給parentform,這個parentform是由GetParentform取得,那么問題就是出在所取得的parentform,它應該是最底端的form,而不是你的控件所在的form。簡單說,keydown時,消息傳錯了form了,不是你預想中的form,因此控制不了你UI
      

  8.   


    还是得转发,用sendmessage?谢谢!
      

  9.   

    可以在主form的keydown事件里,判斷一下,再調用pagecontrol中的form.keydown。不過這樣的代碼,不推薦。
      

  10.   

    你可以把他們放在onshortcut里面做
      

  11.   

    因為針對此問題,你對快捷鍵的傳送有處理過,所以可以在onshortcut做
      

  12.   

    大致這樣procedure TXXXXX.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
    begin
      inherited;
      if msg.CharCode=VK_F7  then
      begin
        edit1.SetFocus; 
        Handled := True;
      end 
      else if msg.CharCode=VK_F8  then  
      begin     
        edit2.SetFocus; 
        Handled := True;
      end 
      else if msg.CharCode=VK_F9  then  
      begin       
        edit4.SetFocus; 
        Handled := True;
      end;
    end;
      

  13.   


    在pagecontrol中的form,己经设置和处理了keydown,而且每一个form都有keydown,这样...
      

  14.   

    那我建議你
    調用Windows.SetParent,不必去指定Form.Parent:= TabSheetXX.
    比如:SetParent(MyForm.Handle,tabsheet.Handle); 
    這樣可以避免getparentform取到最底層的form,也就解決了快捷鍵的傳播問題。可以試試看看
      

  15.   

    windows.SetParent(Form.Handle, tabsheet.Handle);
    用在什么地方?试过了,也许调用不对,不起作用!
      

  16.   

    可以在myform.show之后,多想想嘛....