XLL+ Class Library (6.3)

Using WinForms from an add-in

To use WinForms classes from an add-in you need to add a reference to System.Windows.Forms.dll to your project.

  1. Open the Project Settings window.
  2. Select the page "Common Properties/References".
  3. Click "Add New Reference..." (and prepare for a potentially long wait).
  4. On the ".NET" page, select "System.Windows.Forms", and press "OK".

You may find it convenient to also add the following line to your main source file, which will save quite a bit of typing.

CopyC++
using namespace System::Windows::Forms;

To get access to a class that links XLL+ to the .NET Winforms classes, you should also add the following line to your main source file:

CopyC++
#include <xlpclrforms.h>

ExcelForm

The ExcelForm managed class acts as a link between Excel and WinForms (by implementing the interface IWin32Window). Create an ExcelForm object, and it will allow the Excel application window to act as the owner of a WinForms form.

CopyC++
// Call a WinForms method, using a new instance of  
// the ExcelForm to create an IWin32Window interface 
// for the main Excel application window.
MessageBox::Show(
    gcnew XllPlus::Forms::ExcelForm(),
    "Hello from .NET", ".NET message box", 
    MessageBoxButtons::OK,
    MessageBoxIcon::Hand);

See the ClrDemo sample for an example of the use of ExcelForm.

Next: Deploying your .NET assemblies >>