VSTO 2005 enables developers to create Windows form Action Panes in Word and Excel with only 1 line of code. I will show you how to extend this technique to create an Action Pane using HTML. Why would you want to use HTML for a client side application when you have the power of Windows forms? Well besides to obvious answer of because you can, HTML gives you a quick way to create a visually rich flow layout. And in my next post I will show you how to extend this even further using CSS
Office exposes the Task Pane in ISmartDocument. This is very hard to code against, so the VSTO developers created a generic ActiveX control to be hosted on the Office Task Pane. The ActiveX control also known as the Actions Pane allows you to put any Windows form control in it, including User Controls. Here is where our solution begins. If we look at the available types of controls that ship with Visual Studio we see that there is a WebBrowser control. We can add this control to our User Control
- Create a C# or VB Word or Excel project. In this case I am going to create a VB Word Document project.
- File-New Project –
- Add a User Control to the project.
- Right-click on the project and select Add-New item. Select User Control from the Add new item dialog.
- Add a splitter control to the user control from the control toolbox on the left. Set the dock property to full to make it fill the entire user control and set the orientation to horizontal so that it splits top and bottom.
- Add a button control to the top panel of the splitter control.
- Add a WebBrowser control to the bottom splitter panel. Set the dock property to fill and scrollbars enabled to false.
- Add a HTML page to the project.
- Right-click on the project and select Add-New item. Select HTML Page from the Add new item dialog.
- Wire-up the user control to the word document.
- Wire-up the WebBrowser control to the Windows form user control.
- Load the webpage
- In order for the web browser control to talk to the Windows form control the Windows form control (or whatever object is set as the ObjectForScripting) must have the attribute ComVisible set to true. Here is all the code for the entire user control class