We are using Visio Drawing control in our C# application.
I need to capture the X-axis and Y-axis location of the mouse click when
mouse is clicked on a page in visio document.
You can register on the mousedown event of the visio drawing control:
this.MouseDownEvent += new
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEventHandler(VisioControlEx_MouseDownEvent);
void VisioControlEx_MouseDownEvent(object sender,
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEvent e)
In the AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEvent object
the position of the mouseclick and of the button. (e.button, e.x and
e.y).
The mouse position is returned in doubles and are visio page
coordinates and can be used directly in the shape drop action.
After capturing the location, a new shape must be drawn at the mouse click
location.
first you find the master of the shape you want to drop (via the
stencildocument):
public Master GetMaster(string masterNameU)
{
Masters targetMasters = m_filterStencilDocument.Masters;
foreach (Master m in targetMasters)
if (m.Name == masterNameU)
return m;
Master targetMaster = targetMasters.get_ItemU(masterNameU);
return targetMaster;
}
Then you can use the master to drop it at the desired location (in
your case the caught mouseclick position e.x, e.y)
Master masterShape = GetMaster(name);
((Page)this.Window.PageAsObj).Drop(masterShape, e.x, e.y);