I am trying to create and show a context menu for arcmap desktop 10.2. I have followed the steps in the link provided by esri, which explains that I must override OnContextMenu. I am not sure if I am doing it right and need your help.
What I did was, I got the same code that is provided on the webpage and pasted it in my project, but nothing happens when I right click on the map. I am sure I am missing something.. do I have to register the context menu somewhere ?
I am a nooby it is obvious from my other questions, I do a lot of reading, but it gets very confusing, so I need someone to simplify things a bit.
Here is my understanding of what I should do, and correct me where I am wrong. According to the link provided below, there are two ways to get a context menu to show. either by implementing the ITool.OnContextMenu in case I want the menu to show for a specific tool, or by implementing the IDocumentEvents.OnContextMenu, which for both cases the event OnContextMenu will automatically fire when the user right-clicks on the active view.
The implementation for the event is also provided in the link, which I copied and pasted into VStudio.. now comes the part where I am confused about. how do I get the event to fire ?. When running the project arcmap starts, I right click on the active view, but no menu pops up. do I have to create the menu myself using windows forms?
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000004p9000000
Update, here is a chunk of the code, I want to start listening to those events OnMouseDown and OnContextMenu in this part
public class PTCExternalComponent : BaseTool, ISchematicXmlGenerate, ISchematicXmlUpdate{
private Application _application;
public void GenerateXmlData(string diagramName, string diagramClassName, ref object xmlSource, ref bool cancel) {
cancel = false;
try {
var app = NEAutomation2.Application.Instance().IApplication;
var nameofActivetool = app.CurrentTool.Command.Name;
var activeTool = (ITool)app.CurrentTool;
var toolIndex = app.CurrentTool.Index;
//((IToolbarControlEvents).OnItemClick(ss);
// activeTool.OnMouseDown(0, 0, 0, 0);
var diagramGenerator = DiagramGenerationFactory.GetDiagramGenerator(
diagramName, diagramClassName);
if (diagramGenerator == null) {
Logger.ShowMessageDialog("Unable to find a Diagram Generator for diagram type [" + diagramClassName + "]", true);
} else {
bool canceled;
var diagram = diagramGenerator.GenerateDiagram(out canceled);
var sxg = new SchematicXmlGenerator(diagram, false); // for debugging
if (diagram != null)
xmlSource = sxg.GenerateDiagramXml();
}
} catch (Exception e) {
Logger.ShowMessageDialog(
"An exception occurred while trying to generate diagram of type " +
diagramClassName + "; Exception " + e.Message, true);
ProgressTrackingUtility.HideProgressBar();
}
}
public override void OnMouseDown(int button, int shift, int i, int i1) {
// do stuff here
}
public override bool OnContextMenu(int x, int y) {
//do stuff here
throw new NotImplementedException();
}
object ISchematicXmlGenerate.ApplicationHook {
get { return _application as AppRef; }
set { _application = value as Application; }
}
Rest of Code .....