HTMLWindow3 接口
表示 Visual Studio 集成开发环境 (IDE) 中的 HTML 文档窗口。
命名空间: EnvDTE90
程序集: EnvDTE90(在 EnvDTE90.dll 中)
语法
声明
<GuidAttribute("BAD0A3DD-8109-4684-B806-A5282267BFE4")> _
Public Interface HTMLWindow3
[GuidAttribute("BAD0A3DD-8109-4684-B806-A5282267BFE4")]
public interface HTMLWindow3
[GuidAttribute(L"BAD0A3DD-8109-4684-B806-A5282267BFE4")]
public interface class HTMLWindow3
[<GuidAttribute("BAD0A3DD-8109-4684-B806-A5282267BFE4")>]
type HTMLWindow3 = interface end
public interface HTMLWindow3
HTMLWindow3 类型公开以下成员。
属性
名称 | 说明 | |
---|---|---|
CurrentPane | 获取或设置当前 HTML 编辑器的窗口类型。 | |
CurrentView | 获取或设置 HTML 编辑器窗口在“源”视图、“设计器”视图还是“拆分”视图中。 |
页首
方法
名称 | 说明 | |
---|---|---|
WaitForBackgroundProcessingComplete | 暂停程序执行,直至后台处理完成。 |
页首
备注
当文档是 HTML 文档时,Window 对象的 Object 属性返回 HTMLWindow3。当 CurrentTab 属性设置为 vsHTMLTabsSource 时,Window.Selection 和 Document.Selection 返回一个 TextSelection 对象。
随着 Visual Studio 2008 HTML 编辑器中“拆分”视图的引入,增加了 HTMLWindow3、vsHTMLPanes 和 vsHTMLViews。“拆分”视图将 HTML 编辑器窗口的选项卡和视图元素分隔开来。切换视图(到“设计”或“源”视图)并不一定意味着切换选项卡(“设计”/“拆分”/“源”)。例如,当您单击“拆分”选项卡时,在“设计”和“源”之间切换视图不会更改选项卡,而只会在“拆分”视图中激活或取消激活“设计”和“源”部分。
Visual Studio 2008 HTMLWindow 对象现在还实现 HTMLWindow3 接口,该接口返回当前视图(“设计”或“源”)和当前窗格(“设计”、“源”或“拆分”选项卡)。
HTMLWindow3 规则
HTMLWindow3 的行为是:
Get
当前窗格(选项卡) |
当前视图返回 |
---|---|
vsHTMLViewDesign 或 vsHTMLViewSource,具体取决于哪个部分处于活动状态。 |
Set
当前窗格(选项卡) |
设置 |
---|---|
|
|
|
|
|
示例
Sub HTMLWindow3Example(ByVal dte As EnvDTE80.DTE2)
' Open an HTML document before running this sample.
If TypeOf dte.ActiveDocument.ActiveWindow.Object Is HTMLWindow3 _
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 HTMLWindow3 object and determine which tab is
' currently active.
Dim objHTMLWin As HTMLWindow3 = _
CType(dte.ActiveDocument.ActiveWindow.Object, HTMLWindow3)
Dim Tab As vsHTMLTabs = CType(objHTMLWin.CurrentTab, _
vsHTMLTabs)
Dim cpane As vsHTMLPanes = vsHTMLPanes.vsHTMLPaneSplit
' Switch to the "split" view, source view.
objHTMLWin.CurrentPane = vsHTMLPanes.vsHTMLPaneSplit
objHTMLWin.CurrentView = vsHTMLViews.vsHTMLViewSource
' Get an EditPoint at the start of the text.
Dim objTextWin As TextWindow = _
CType(objHTMLWin.CurrentTabObject, TextWindow)
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 HTMLWindow3)
{
HTMLWindow3 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 HTMLWindow3 object and determine which tab is
// currently active.
objHTMLWin = dte.ActiveDocument.ActiveWindow.Object as
HTMLWindow3;
Tab = objHTMLWin.CurrentTab;
// Switch to the "source" tab.
objHTMLWin.CurrentPane = vsHTMLPanes.vsHTMLPaneSplit;
objHTMLWin.CurrentTab = vsHTMLViews.vsHTMLViewSource;
// 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.");
}