# ToolWindow class
{: .no_toc }

A dockable / floating IDE pane whose contents are rendered as HTML. Created by [**ToolWindows.Add**](/tB/Packages/tbIDE/ToolWindows.md#add); the addin populates its DOM through the [**RootDomElement**](#rootdomelement) --- an [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md) at the root of the pane --- and shows the pane by setting [**Visible**](#visible) = **True** (tool windows start out invisible).

```tb check_build
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
```

The pane first shows floating over the IDE, centred in its window, at the suggested size:

![A floating tool window titled Hello from My AddIn, 400 by 300 pixels, holding the heading Hello, world!](/Reference/Built-In/tbIDE/Images/ToolWindow.png){:width="400" height="300"}

The user can dock it as the IDE's own panels are docked, by dragging the grip at the left of its title bar onto the edge of a docked panel. Here it is dropped on the top edge of PROPERTIES:

![The right-hand column of the IDE: PROJECT EXPLORER, then the tool window Hello from My AddIn docked under it, then the header of PROPERTIES.](/Reference/Built-In/tbIDE/Images/ToolWindow_Docked.png){:width="267" height="668"}

A `WithEvents` reference receives [**OnClose**](#onclose) when the user dismisses the pane --- typically the addin uses that event to release any per-window state (timers, references to DOM elements …).

* TOC
{:toc}

## Tool-window default member --- jQuery-style child lookup

[**RootDomElement**](#rootdomelement) is the **DefaultMember** of the **ToolWindow** interface --- so `myToolWindow.(...)` is equivalent to `myToolWindow.RootDomElement.Properties.(...)`. Because [**HtmlElementProperties**](/tB/Packages/tbIDE/HtmlElementProperties.md) 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:

```tb check_build
' Find the descendant element whose id is "dataEntry" and read its .Value:
Dim entered As String = myToolWindow("#dataEntry").Value
```

Useful for accessing a single child element by ID without holding a separate `As HtmlElement` reference for it.

## Suggested initial size

[**RootDomElement**](#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**](/tB/Packages/tbIDE/ToolWindows.md#add)'s persistence ID), the IDE remembers the user's chosen size and the suggested values are ignored.

The IDE sets each value as the floating pane's CSS `width` or `height`, then centres the pane in its window. So any CSS length works, including `vw` and `vh`, which are relative to the IDE's window. A pane that should fit in a small IDE window can cap its size with `min()`:

```tb
With myWindow.RootDomElement
    .Properties.suggestedWidth = "min(480px, 85vw)"
    .Properties.suggestedHeight = "min(640px, 85vh)"
End With
```

With fixed sizes only, a pane opened in a small IDE window is larger than the window.

> [!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**](/tB/Packages/tbIDE/ToolWindows.md#add)), the IDE-remembered size wins.

## Properties

### Name
{: .no_toc }

The internal name supplied to [**ToolWindows.Add**](/tB/Packages/tbIDE/ToolWindows.md#add). **String**, read-only.

### Resizable
{: .no_toc }

Whether the user is allowed to resize the pane. **Boolean**, read / write. Default **True**.

Syntax: *toolWindow*.**Resizable** [ = *value* ]

### RootDomElement
{: .no_toc }

The root [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md) of the pane's DOM. **DefaultMember** --- see [Tool-window default member](#tool-window-default-member--jquery-style-child-lookup) above.

Syntax: *toolWindow*.**RootDomElement** **As** [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md)

### Title
{: .no_toc }

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
{: .no_toc }

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* ]

> [!NOTE]
> Showing the pane sets the `display` style of [**RootDomElement**](#rootdomelement) to `block`, replacing any value the addin gave it. Put a flex or grid layout on a child element of the root instead, and give both the root and that child a `height` of `100%` for the layout to fill the pane.

## Methods

### ApplyCss
{: .no_toc }

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**](/tB/Packages/tbIDE/HtmlElementProperties.md).

Syntax: *toolWindow*.**ApplyCss** *styles*

*styles*
: *required* The CSS text. **String**.

```tb check_build
' Load CSS from an embedded resource:
Dim css As String = StrConv(LoadResDataInternal("styles.css", "STYLESHEETS"), VbStrConv.vbFromUTF8)
myToolWindow.ApplyCss css
```

### Close
{: .no_toc }

Closes the pane. The matching [**OnClose**](#onclose) event fires before the call returns.

Syntax: *toolWindow*.**Close**

## Events

### OnClose
{: .no_toc }

Fires when the pane is closed --- either by the user dismissing it or by the addin calling [**Close**](#close). Use this to release any per-window state (timers, references to DOM elements, …).

Syntax: *toolWindow*_**OnClose**()
