spilon

Using the Visual Studio designer to easily build a ProcessBook Docking Window

Discussion created by spilon on Jun 10, 2009
Latest reply on Dec 6, 2010 by spilon

As you may already know, we provide templates to develop PI ProcessBook 3.x .NET Add-Ins (they were explained in this webinar and are available on the vCampus Download Center). This post is related to one of those 4 templates: the Docking Window Add-In.

 

In the Visual Studio 2005 version of this template, a PBControlView object named ctrlView is added to the docking window (m_dockWindow variable in the Connect class). On this view, a label is then created:

ctrlView.CreateControl("{978C9E23-D4B0-11CE-BF2D-00AA003F40D0}")
  //or
ctrlView.CreateControl("Forms.Label.1")

 

----> Yes, you are right: this is a COM control, not a .NET one!
----> And yes, you are right again: we are not using the Form/UserControl designer provided in Visual Studio, which most people are using on a regular basis.

 

 

 

The good news is: there is a way for you to easily design a .NET UserControl with the Visual Studio designer and then have the docking window load it. Here's how you can do this in 5 simple steps:

 

1. Add a .NET User Control to your VB.NET or C# add-in project
090610_2D00_UserControlInPBDockWindow1.jpg

 

2. Double-click on the User Control in the Solution Explorer - you'll get in design mode.

 

3. Resize the User Control, add the controls (and the code) you want
  (Hint: if you have a control which you want to occupy the whole docking window (e.g. TreeView), you can "dock it in the parent container" as shown in the screenshot below. That way you don't have to write code to handle resizing of the docking window by the user in ProcessBook )
090610_2D00_UserControlInPBDockWindow2.jpg

 

4. Jump in the code for your User Control and make it visible to COM
(Remember: PI ProcessBook is COM-based... which means that under the hood, the PBControlView.CreateControl method - which we'll use in the next step) expects to create COM controls)

 

    In VB.NET:
    090610_2D00_UserControlInPBDockWindow3.jpg

 

    In C#:
    090610_2D00_UserControlInPBDockWindow4.jpg

 

5. Back to the code in the OnConnection method of the Connect class, get the PBControlView to load that ".NET-but-COM-visible control"
(and keep a reference to it for future usage:

 

    In VB.NET:   

Dim usrCtrl As UserControl1 = DirectCast( _
    ctrlView.CreateControl("AddinPBDockWin_VB1.UserControl1"), UserControl1)

 

    In C#:    

UserControl1 usrCtrl = 
        (UserControl1)ctrlView.CreateControl("AddInPBDockWin_CS1.UserControl1");

 

Hope this helps!

Outcomes