Context Menu Popup

A

Ashok

Hi

I have written code to intiate a context menu in Mouse up
event of Visio drawing control using c# application. when
i pass the parameters as context menu and e.x and e.y for
the position, it is taking the x,y of Visio scale and
trying to locate the same on the screen.

As a result the menu pops up but it get displayed as per
the scale in the screen. Is there any way of conversion
required to show the menu on the same place of the click?

Any thoughts or help will be greatfull.

Regards
Ashok Kumar MVN
 
B

Bill K. [MSFT]

Below is a method to do the conversion (this method will be included in the
Microsoft Visio 2003 SDK).

/// <summary>The MapVisioToWindows method converts Visio coordinates to
/// Windows coordinates.</summary>
/// <remarks>The conversion includes changing from Visio's coordinate
/// system (inches) to the Windows coordinate system (pixels). The
/// conversion of the Y coordinate must also take into the account the
/// different locations of the origin, since Visio's origin is at the
/// lower-left corner and the Windows origin is at the upper-left
/// corner.</remarks>
/// <param name="drawingControl">Drawing control with the Visio window
/// to use.</param>
/// <param name="visioX">X position in the Visio coordinate system.
/// </param>
/// <param name="visioY">Y position in the Visio coordinate system.
/// </param>
/// <returns>Point containing the given Visio coordinate in Windows
/// coordinates.</returns>
[CLSCompliant(false)]
public static System.Drawing.Point MapVisioToWindows(
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl,
double visioX,
double visioY) {

// The drawing control object must be valid.
if (drawingControl == null) {

// Throw a meaningful error.
throw new ArgumentNullException("drawingControl");
}

int windowsX = 0;
int windowsY = 0;
double visioLeft;
double visioTop;
double visioWidth;
double visioHeight;
int pixelLeft;
int pixelTop;
int pixelWidth;
int pixelHeight;
Window referenceWindow;

referenceWindow = (Window)drawingControl.Window;

// Get the window coordinates in Visio units.
referenceWindow.GetViewRect(out visioLeft, out visioTop,
out visioWidth, out visioHeight);

// Get the window coordinates in pixels.
referenceWindow.GetWindowRect(out pixelLeft, out pixelTop,
out pixelWidth, out pixelHeight);

// Convert the X coordinate by using pixels per inch from the
// width values.
windowsX = (int)(pixelLeft +
((pixelWidth / visioWidth) * (visioX - visioLeft)));

// Convert the Y coordinate by using pixels per inch from the
// height values and transform from a top-left origin (windows
// coordinates) to a bottom-left origin (Visio coordinates).
windowsY = (int)(pixelTop +
((pixelHeight / visioHeight) * (visioTop - visioY)));

return new System.Drawing.Point(windowsX, windowsY);
}


Hope this helps,
 
K

Kannan.M.R

Use this piece of cod

pagObj = appln.ActivePage
shpsObj = pagObj.Shapes
if(e.button == (int)Microsoft.Office.Interop.Visio.VisKeyButtonFlags.visMouseRight

foreach(Shape shpObj in shpsObj) //Loop thro the shapes to identify the shape clicke

if(shpObj.HitTest(e.x,e.y,0.0) == (int)Microsoft.Office.Interop.Visio.VisHitTestResults.visHitInside) //get the co-ordinates of the shape clicke

objSelect = appln.ActiveWindow.Selection; //get the selected shap
e.cancelDefault = true; //Cancel the default menu provided by window
cntxMenu.Show(this,Create(ref drawingControl,e.x,e.y)); //display the context menu create
break



}

//This Functio maps visio co-ordinates to window co-ordinate
private static Point Create(ref AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl, double x, double y)

double viewLeft, viewTop, viewWidth, viewHeight
drawingControl.Window.GetViewRect(out viewLeft,out viewTop,out viewWidth, out viewHeight)
int xForm = (int) (drawingControl.Left + (drawingControl.Width/viewWidth) *(x-viewLeft)); //The X co-ordinate that is to be got
int yForm = (int)(drawingControl.Top + (drawingControl.Height / viewHeight) * (viewTop - y)); //The Y co-ordinate that is to be go
return new Point(xForm,yForm)


Hope that helps
 
K

Kiran Nakhate

Hi Ashok,

I wanted to know about the popup menus, which are poping up on Visio ActiveX
control.
I want to totally avoid the default popup menus & show custom one.

Here, I could able to show the custom one. Sometimes, the default popup
menus will come automatically.
Can you please suggest me how to control it.

With Regards,
Kiran Nakhate,
Email: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top