Hi All
I am attempting to add a custom window to an addin and have used Sparx's rather brief notes
http://sparxsystems.com/enterprise_architect_user_guide/13.5/automation/custom_docked_window.htmlHowever the addiin window is not added:
I am using Visual Studio 2013 and C# .Net 4.5
My Code is as below:
The very simple Test Addin:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestAddIn
{
public class TestAddIn
{
// ----------------------------------------------------------------------
// Menu Strings
// ----------------------------------------------------------------------
private String menuHeader = null;
private String[] menuOptions = { null };
private bool safeDeleteIsEnabled;
private MyCustomControl myCustomControl;
//-----------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------
public TestAddIn()
{
safeDeleteIsEnabled = true;
menuHeader = "-&Tester";
menuOptions = new String[] { "&Checked", "-", "&Unchecked", "-", "&Show Window", "&Hide Window"};
}
// Enterprise Architect standard extension methods
public void EA_Connect(EA.Repository repository)
{
myCustomControl = (MyCustomControl)repository.AddWindow
("Test Addin", "TestAddIn.MyCustomControl");
if (myCustomControl == null)
{
MessageBox.Show("Test AaddIn Custom Window not added");
}
else
{
MessageBox.Show("Test AddIn Custom Window added);
}
}
public void EA_Disconnect()
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
public object EA_GetMenuItems(EA.Repository repository,
string menuLocation,
string menuName)
{
if (menuName == String.Empty)
{
//return top level menu option
return menuHeader;
}
if (menuName == this.menuHeader)
{
// return submenu options
return menuOptions;
}
else
{
return string.Empty;
}
}
public void EA_GetMenuState(EA.Repository repository,
string menuLocation,
string menuName,
string itemName,
ref bool isEnabled,
ref bool isChecked)
{
switch (menuLocation)
{
case "MainMenu":
switch (itemName)
{
case "&Checked":
isEnabled = true;
isChecked = safeDeleteIsEnabled;
break;
case "&Unchecked":
isEnabled = true;
isChecked = !safeDeleteIsEnabled;
break;
}
break;
}
}
public void EA_MenuClick(EA.Repository repository,
string menuLocation,
string menuName,
string itemName)
{
switch (itemName)
{
case "&Checked":
safeDeleteIsEnabled = !safeDeleteIsEnabled;
break;
case "&Unchecked":
safeDeleteIsEnabled = !safeDeleteIsEnabled;
break;
}
}
}
}
The addin window has been added to the solutions as a Visual Studio Custom Control and the Code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestAddIn
{
public partial class MyCustomControl : Control
{
public MyCustomControl()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Everything builds fine and the addin works fine, but the reference nyCustomControl is always null thus indicating the Custom Window has not not been added.
Using the Extend | Manage | Add-in Windows returns No loaded add-ins are using this window
I must be missing something, but what?
All namespaces and names are correct.s
One curious thing, the article by Sparx on Custom Windows, mentions an ActiveX Custom Control and and OCX file. I do not see any OCX file in my build, so if this is what is missing, how is such an OCX file created, and where should it be located.
Any help or advice will be most appreciated.
Phil