共用方式為


HTMLWindow 介面

代表一個 HTML 文件視窗。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
<GuidAttribute("F6576203-FBCE-477E-A66B-EDA237BB68A7")> _
Public Interface HTMLWindow
[GuidAttribute("F6576203-FBCE-477E-A66B-EDA237BB68A7")]
public interface HTMLWindow
[GuidAttribute(L"F6576203-FBCE-477E-A66B-EDA237BB68A7")]
public interface class HTMLWindow
[<GuidAttribute("F6576203-FBCE-477E-A66B-EDA237BB68A7")>]
type HTMLWindow =  interface end
public interface HTMLWindow

HTMLWindow 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 CurrentTab 取得或設定在 HTML 編輯視窗中 [來源] 或 [設計工具] 索引標籤的狀態 (使用中或非使用中)。
公用屬性 CurrentTabObject 取得或設定在 HTML 編輯視窗中 [來源] 或 [設計工具] 索引標籤的狀態 (使用中或非使用中)。
公用屬性 DTE 取得最上層的擴充性物件。
公用屬性 Parent 取得 HTMLWindow 物件的直接上層父物件。

回頁首

備註

當文件為 HTML 文件時,Window 物件的 Object 屬性會傳回 HTMLWindow。 HTMLWindow.CurrentTab 屬性設定為 vsHTMLTabsSource 時,Window.Selection 和 Document.Selection 會傳回 TextSelection 物件。

範例

Sub HTMLWindowExample(ByVal dte As EnvDTE.DTE)
    ' Open an HTML document before running this sample.
    If TypeOf dte.ActiveDocument.ActiveWindow.Object Is HTMLWindow Then
        ' Ask the user for a file to insert into the body of the HTML 
        ' document. This file should be an HTML fragment.
        Dim strFile As String = InputBox("Enter the name of a file to _
        insert at the end of the HTML document:")
        ' Get the HTMLWindow object and determine which tab is 
        ' currently active.
        Dim objHTMLWin As HTMLWindow = _
        dte.ActiveDocument.ActiveWindow.Object
        Dim Tab As vsHTMLTabs = objHTMLWin.CurrentTab

        ' Switch to the "source" tab.
        objHTMLWin.CurrentTab = vsHTMLTabs.vsHTMLTabsSource

        ' Get an EditPoint at the start of the text.
        Dim objTextWin As TextWindow = objHTMLWin.CurrentTabObject
        Dim objEP As EditPoint = _
        objTextWin.ActivePane.StartPoint.CreateEditPoint

        ' Look for the end of the document body.
        If objEP.FindPattern("</body>") Then
            ' Insert the contents of the file.
            objEP.InsertFromFile(strFile)
        End If

        ' Switch back to the original view of the HTML file.
        objHTMLWin.CurrentTab = Tab
    Else
        MsgBox("You must open an HTML document.")
    End If
End Sub
public void HTMLWindowExample(_DTE dte)
{
    // Open an HTML document before running this sample.
    if (dte.ActiveDocument.ActiveWindow.Object is HTMLWindow)
    {
        HTMLWindow objHTMLWin;
        vsHTMLTabs Tab;
        String strFileName;
        // Ask the user for a file to insert into the body of the HTML 
        // document. This file should be an HTML fragment.
        strFileName = Microsoft.VisualBasic.Interaction.InputBox 
        ("Enter the name of a file to insert at the end of the HTML 
        document:","","",100,100);
        // Get the HTMLWindow object and determine which tab is 
        // currently active.
        objHTMLWin = dte.ActiveDocument.ActiveWindow.Object as 
        HTMLWindow;
        Tab = objHTMLWin.CurrentTab;

        // Switch to the "source" tab.
        objHTMLWin.CurrentTab = vsHTMLTabs.vsHTMLTabsSource;

        // Get an EditPoint at the start of the text.
        TextWindow objTextWin;
        EditPoint ep;
        EditPoint ep2 = null;
        TextRanges textRanges = null;
        objTextWin = objHTMLWin.CurrentTabObject as TextWindow;
        ep = objTextWin.ActivePane.StartPoint.CreateEditPoint();
        textRanges = objTextWin.Selection.TextRanges;

        // Look for the end of the document body.
        if (ep.FindPattern 
        ("</body>",(int)vsFindOptions.vsFindOptionsNone, ref ep2, ref 
        textRanges))
            // Insert the contents of the file.
            ep.InsertFromFile (strFileName);
            // Switch back to the original view of the HTML file.
            objHTMLWin.CurrentTab = Tab;
    }
    else
        MessageBox.Show ("You must open an HTML document.");
}

請參閱

參考

EnvDTE 命名空間