Sei sulla pagina 1di 4

Dot net Add-in Tutorial - VB

Add-ins can be used to create custom panes. This example demonstrates how to create a custom pane using Visual Basic 2005 Express. 1. Launch Visual Basic 2005 Express. Create a new Class Library project (File - New Project, Class Library) named MyPane. 2. In the Solution Explorer window, right click Class1.vb and select Delete. 3. In the Solution Explorer window, right click MyPane and select Add - User Control. Set the control name to MyPaneControl and click Add. 4. In the MyPaneControl.vb design window, add a button (Toolbox, Common Controls, Button) and a label (Toolbox, Common Controls, Label). Double click the button to add a handler for the button's Click event. 5. In the Solution Explorer window, right click MyPane and select Add Reference. In the Add Reference dialog, switch to the Browse tab, locate the Manifold installation folder, select Manifold.Interop.dll and Manifold.Interop.Scripts.dll and click OK. 6. In the MyPaneControl.vb code window, select all text and replace it with: Public Class MyPaneControl Implements Manifold.Interop.Scripts.IEventsConnection Dim app As Manifold.Interop.Application Private Sub Button1_Click( _
Gustavo Palminha: gustavopalminha@hotmail.com

ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If Not (app Is Nothing) Then app.MessageBox("The document contains " + _ app.ActiveDocument.ComponentSet.Count.ToString() + _ " component(s).") End If End Sub Public Sub ConnectEvents( _ ByVal ev As Manifold.Interop.Scripts.Events) _ Implements Manifold.Interop.Scripts.IEventsConnection.ConnectEvents AddHandler ev.DocumentClosed, AddressOf Document_Changed AddHandler ev.DocumentCreated, AddressOf Document_Changed AddHandler ev.DocumentOpened, AddressOf Document_Changed AddHandler ev.DocumentSaved, AddressOf Document_Changed End Sub Private Sub Document_Changed( _ ByVal sender As System.Object, _ ByVal args As Manifold.Interop.Scripts.DocumentEventArgs) app = args.Document.Application Label1.Text = args.Document.Path End Sub End Class

7. Invoke Project - Show All Files. In the Solution Explorer window, expand MyPane then MyProject and finally double click AssemblyInfo.vb. Locate the line which sets the value of the ComVisible attribute to False, and change it to set the value of the attribute to True: <Assembly: ComVisible(True) > 8. Build the class library by using Build - Build MyPane. Make sure there are no build errors. 9. Save the code and the compiled binary by using File - Save All. 10. Launch Windows Explorer and locate the folder you saved the project to. Descend into bin\release, copy MyPane.dll and paste it into the Manifold configuration folder (usually, C:\Program Files\Manifold System\Config). If you do not have write permissions in the configuration folder, launch Manifold and change the file location for that folder to point to where you have write permissions. 11. In Windows Explorer, create a new XML file in the configuration folder and name it MyPane.xml for convenience (this file is different from MyPane.xml generated
Gustavo Palminha: gustavopalminha@hotmail.com

by Visual Basic). Drag and drop the created MyPane.xml into the opened instance of Visual Basic, set its text to: <?xml version="1.0"?> <xml> <addin> <name>My Pane</name> <command> <name>My Pane</name> <form>MyPane.dll;MyPane.MyPaneControl</form> </command> </addin> </xml> Save the MyPane.xml file. That's all! To test the pane, launch a new instance of Manifold. Note that the Tools - Add-Ins menu contains a new command named My Pane. Invoke that command to show the pane. Create a new project. The pane label should become blank. Create a new drawing, then press the pane button. The pane should report that the project .map file contains two components (a drawing and a table). Save the project. The pane label should update its text with the path to the .map file. Add-ins and Forms Add-ins can include forms, used as modeless panes. Forms can be either ActiveX controls or .NET controls. To include a form into an add-in, create a command item using the <command> tag, supply the name of the form using the <name> tag and supply either the ProgID of the ActiveX control or the name of the .NET control using the <form> tag. The name of the .NET control should include the name of the assembly or path to the assembly module (either absolute or relative from the Config folder) and the name of the .NET class separated by a semicolon. Tech Tips Manifold cannot use any customizations if the .xml files do not contain XML that is exactly correct. A useful test before launching Manifold is to open any newly created or modified .xml file in Internet Explorer. Internet Explorer will show a correct .xml file in

Gustavo Palminha: gustavopalminha@hotmail.com

a simple text format. If Internet Explorer cannot parse the .xml file, Manifold won't be able to either. Add-in forms implemented as .NET controls can subscribe to events fired by the Manifold core at runtime. To do this, include a reference to Manifold.Interop.dll and Manifold.Interop.Scripts.dll, implement the IEventsConnection interface from the latter dll and add handlers to the desired events in the ConnectEvents method of the interface.

Gustavo Palminha: gustavopalminha@hotmail.com

Potrebbero piacerti anche