2009-05-28 15 views
3

二つの簡単な質問私はTWebBrowserにフォーカスを設定するにはどうすればよいデルファイ - TWebBrowserは

  1. を発行しますか?これは、TWebBrwoser表示領域内を最初にクリックすることなく、マウスホイールがディスプレイをスクロールするためです。それは何もしない(または何もしないように思われる)setfocusメソッドを持っています。

  2. TWebBrowser内で、表示されたリンクを右クリックし、[プロパティ]を選択します。 [OK]ボタンと[キャンセル]ボタンは無効になっており、ダイアログを閉じることはできません。あなたはそれを殺すためにあなたのアプリを終了する必要があります。

ありがとう、 Jason。多くのウェブ狩猟後の質問1について

+0

だから別に質問するのが最善です。 SOのポイントは、質の高い回答を持つ質問のリポジトリを作成することです。あなたがあなたの質問に2つの別々の答えを得たら、あなたは受け入れますか? – Argalatyr

+0

意味があります。私は将来別々の質問を作成します。 Jason。 –

答えて

6

回答....

with WebBrowser1 do 
if Document <> nil then 
with Application as IOleobject do 
DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle, GetClientRect); 
0

これはピーター・ジョンソン、How to make a TWebBrowser become the active control when clickedによって、次の資料に記載されています。 、あなたはそれをすべて読んで確認してくださいより多くの詳細は、記事にある

procedure TWebBrowserFrame.CommandStateChange(Sender: TObject; 
    Command: Integer; Enable: WordBool); 
var 
    Doc: IHTMLDocument2;  // document object 
    Sel: IHTMLSelectionObject; // current selection 
begin 
    // Check we have a valid web browser triggering this event 
    if not Assigned(Sender) or not (Sender is TWebBrowser) then 
    Exit; 
    // Check we have required command 
    if TOleEnum(Command) <> CSC_UPDATECOMMANDS then 
    Exit; 
    // Get ref to document object and check not nil 
    Doc := Browser.Document as IHTMLDocument2; 
    if not Assigned(Doc) then 
    Exit; 
    // Get ref to current selection 
    Sel := Doc.selection as IHTMLSelectionObject; 
    // If selection is of correct type then we have a mouse click 
    if Assigned(Sel) and (Sel.type_ = 'Text') then 
    begin 
    // Make the web browser the form's active control 
    (Sender as TWebBrowser).SetFocus; 
    Doc.parentWindow.focus; 
    end; 
end; 

:このOnCommandStateChangeイベントを追加し、頻繁に要約する

+0

このコードを入手した記事の参照で編集しました。帰属なしでコードを投稿しないでください。 –