ToolWindow class
A dockable / floating IDE pane whose contents are rendered as HTML. Created by ToolWindows.Add; the addin populates its DOM through the RootDomElement — an HtmlElement at the root of the pane — and shows the pane by setting Visible = True (tool windows start out invisible).
Private WithEvents myWindow As ToolWindow
Private Sub Button1_OnClick()
Set myWindow = Host.ToolWindows.Add("MyAddIn.MyWindow", "MyAddIn.MyWindowPosition")
With myWindow
.Title = "Hello from My AddIn"
With .RootDomElement
.Properties.suggestedWidth = "400px"
.Properties.suggestedHeight = "300px"
With .ChildDomElements.Add("greeting", "h1")
.Properties.innerText = "Hello, world!"
End With
End With
.Visible = True
End With
End Sub
Use the WithEvents reference to receive OnClose when the user dismisses the pane — typically the addin uses that event to release any per-window state (timers, references to DOM elements …).
- Tool-window default member — jQuery-style child lookup
- Suggested initial size
- Properties
- Methods
- Events
Tool-window default member — jQuery-style child lookup
RootDomElement is the DefaultMember of the ToolWindow interface — so myToolWindow.(...) is equivalent to myToolWindow.RootDomElement.Properties.(...). Because HtmlElementProperties is [COMExtensible(True)], a string passed in parenthesis-syntax is resolved against the DOM at run time. The IDE treats CSS-style selectors specially, so:
' Find the descendant element whose id is "dataEntry" and read its .Value:
Dim entered As String = myToolWindow("#dataEntry").Value
Useful for grabbing a single child element by ID without holding a separate As HtmlElement reference for it.
Suggested initial size
RootDomElement accepts .Properties.suggestedWidth and .Properties.suggestedHeight (CSS-length strings like "400px"). These are one-shot hints — used the first time the tool window opens as a floating pane; once the user resizes (or after position persistence kicks in through ToolWindows.Add’s persistence ID), the IDE remembers the user’s chosen size and the suggested values are ignored.
Note
Set suggestedWidth / suggestedHeight before the first time the pane becomes visible. If the pane has previously been opened by this user (and a persistence ID was supplied to ToolWindows.Add), the IDE-remembered size wins.
- TOC
Properties
Name
The internal name supplied to ToolWindows.Add. String, read-only.
Resizable
Whether the user is allowed to resize the pane. Boolean, read / write. Default True.
Syntax: toolWindow.Resizable [ = value ]
RootDomElement
The root HtmlElement of the pane’s DOM. DefaultMember — see Tool-window default member above.
Syntax: toolWindow.RootDomElement As HtmlElement
Title
The pane’s title-bar text. String, read / write. Update at any time to reflect changing state (selection counts, dirty markers, …).
Syntax: toolWindow.Title [ = value ]
Visible
Whether the pane is shown. Boolean, read / write. Default False — newly-created tool windows are invisible until the addin sets this to True.
Syntax: toolWindow.Visible [ = value ]
Methods
ApplyCss
Injects a <style> block into the pane’s DOM that applies to every element inside the pane. Useful for global CSS — class selectors, custom-element styling, hover effects — that would be awkward to set element-by-element through HtmlElementProperties.
Syntax: toolWindow.ApplyCss styles
- styles
- required The CSS text. String.
' Load CSS from an embedded resource:
Dim css As String = StrConv(LoadResData("styles.css", "STYLESHEETS"), VbStrConv.vbFromUTF8)
myToolWindow.ApplyCss css
Close
Closes the pane. The matching OnClose event fires before the call returns.
Syntax: toolWindow.Close
Events
OnClose
Fires when the pane is closed — either by the user dismissing it or by the addin calling Close. Use this to release any per-window state (timers, references to DOM elements, …).
Syntax: toolWindow_OnClose()