Hi, there: Both of these scenarios are supported by the ActiveX control.
Here's some C# sample code to demonstrate this. Use Win32's "GetTickCount"
function from C++. VB6 has a Timer function. Spatial proximity may matter to
some folks. If so, they need to track the x and y from the events also.
C#:
private void axDrawingControl1_MouseDownEvent(object sender,
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEvent e)
{
// Have a class member like this in the containing
form's class definition:
//
//private int m_previousMouseDownEvent= 0;
const int threshold= 200;
if (0!=m_previousMouseDownEvent &&
(System.Environment.TickCount-m_previousMouseDownEvent)<threshold)
{
// Two MouseDown events occurred within threshold
milliseconds
// of each other... Consider it a "double
click"...
//
System.Windows.Forms.MessageBox.Show("Double
clicked!");
}
m_previousMouseDownEvent = System.Environment.TickCount;
}
Here's some sample code demonstrating how to replace the default Visio RMA
with a custom menu with a single option (again in C#). Sorry, the formatting
got a little lost. I've also included a couple of helper functions too.
private void axDrawingControl1_MouseUpEvent(object sender,
AxVisOcx.EVisOcx_MouseUpEvent e)
{
if (e.button == (int) Visio.VisKeyButtonFlags.visMouseRight)
{
//need a reference to the shape that was clicked for the context menu
this.clickedShape = VisioUtility.GetClickedShape( VisPage, e.x, e.y );
if (this.clickedShape != null)
{
//cancel the default Visio RMA
e.cancelDefault = true;
//call utility function to translate Visio page units to pixels.
CtxMenuShape.Show(
this,
PageUnitsToPixels( ref axDrawingControl1, e.x, e.y));
}
}
}
public static Shape GetClickedShape( Page visioPage, double x, double y,
double tolerance )
{
try
{
Selection visSelection = visioPage.get_SpatialSearch(
x,
y,
(short) VisSpatialRelationCodes.visSpatialContainedIn,
tolerance,
(short) VisSpatialRelationFlags.visSpatialFrontToBack);
if (visSelection.Count > 0 )
{
// 1 based collection
Debug.WriteLine( visSelection[1].Name);
return (Shape) visSelection[1];
}
else
{
return null;
}
}
catch( Exception exp)
{
Debug.WriteLine( exp.Message );
throw exp;
}
}
private Point PageUnitsToPixels( ref
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl axDrawingControl, double
x, double y)
{
double vLeft, vTop, vWidth, vHeight;
axDrawingControl.Window.GetViewRect( out vLeft, out vTop, out vWidth, out
vHeight);
// calculate position
int xForm = (int) (axDrawingControl.Left +
(axDrawingControl.Width/vWidth)*(x-vLeft));
int yForm = (int) (axDrawingControl.Top +
(axDrawingControl.Height/vHeight)*(vTop-y));
return new Point( xForm, yForm );
}
Mai-lan
--
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Matt said:
Hi Andrew
You really should read the article with the link I posted first . It gives
you a better understanding how the drawingcontrol (ActiveX control) works.
It won't let you execute any VBA in it but you can reach the objects
(shapes, pages, documents etc.) very good from your outside host
application.
Pls. also have a look in the other newsgroup I mentioned before - meanwhile
I found a solution how to create dbl-clicks in the control (it's a bit
of
a
hack and I'm still waiting for some feedback from the Pros, but so far it
works really good for me).
Instead of the msgbox, I'm calling in this procedure you could call your
custom-menu or a form you might have designed as a context-menu (just define
it as popup without any closing, mini- and maximzing buttons)
Regards
MAtt