How to translate a PinX and PinY of a shape to a windows screen po

D

Dr. Alaa Serry

I have a PinX and PinY of a shape and I would like to convert it to a window
screen location so that I can position a context menu at that location.
I am using the Visio 2003 drawing control within a windows application
written in C#.

Thank you kindly
/alaa
 
R

Roger

Hello Alaa
The Visio 2003 SDK Code Librarian contains some example C# code showing how
to convert Visio co-ordinates to Windows screen co-ordinates.
I hope this helps
Roger Billsdon
 
D

Dr. Alaa Serry

Thanks Roger.
I tried yesterday to locate such an example but I was unscuccessful. I would
appretiate if somebody could kindly point me to that code.
Thanks./alaa
 
A

Al Edlund

John Marshall was recently sharing this..
al

Public Sub XYTest()



Dim shpObj As Visio.Shape

Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double



x1 = 0

y1 = 0



For Each shpObj In ActivePage.Shapes

shpObj.XYToPage x1, y1, x2, y2

Debug.Print x1, y1, x2, y2



shpObj.XYFromPage x1, y1, x2, y2

Debug.Print x1, y1, x2, y2

Next shpObj



End Sub
 
D

Dr. Alaa Serry

Thanks Al. I am not sure that that would solve my problem.
Please refer to code below:

private void mf_MouseUpEvent(object sender,
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseUpEvent e)
{ short m_Hit = m_VisioSelectedShape.HitTest(e.x, e.y, 0.0001);
if ( e.button == 2 // Right Button
&& m_VisioSelection.Count == 1 // There is only one
selected shape
&& m_Hit > 0 // The hit was at the
selected shape
) mf_DisplayShapeInfo(e.x, e.y);
}
#endregion

What I need is to translate the e.X and e.Y from Visio coordinate to screen
coordinates.

Thanks
 
A

Al Edlund

I apologize for the unintentional misdirection. This from the visio sdk,
al

// ConvertCoordinates.cs
// <copyright>Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <summary>This class contains code that converts coordinates between the
// Visio coordinate system and the Windows screen coordinate
system.</summary>

using System;

namespace Microsoft.Samples.Visio.CSharp {

/// <summary>The ConvertCoordinates class is used to convert coordinates
/// between the Visio coordinate system and the Windows screen coordinate
/// system.</summary>
public sealed class ConvertCoordinates {

/// <summary>This constructor is intentionally left blank.</summary>
private ConvertCoordinates() {

// No initialization is required.
}

/// <summary>The MapDrawingToScreen method converts Visio coordinates to
/// Windows screen coordinates.</summary>
/// <remarks>The conversion includes changing from Visio's coordinate
/// system (inches) to the Windows screen 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="referenceWindow">Reference to a Visio window</param>
/// <param name="drawingX">X position in the Visio coordinate system
/// </param>
/// <param name="drawingY">Y position in the Visio coordinate system
/// </param>
/// <returns>Point containing the given Visio coordinate in Windows
/// coordinates</returns>
public static System.Drawing.Point MapDrawingToScreen(
Microsoft.Office.Interop.Visio.Window referenceWindow,
double drawingX,
double drawingY) {

double drawingLeft;
double drawingTop;
double drawingWidth;
double drawingHeight;
int screenLeft;
int screenTop;
int screenWidth;
int screenHeight;
int screenX = 0;
int screenY = 0;

try {

// Get the window coordinates in Visio units.
referenceWindow.GetViewRect(out drawingLeft, out drawingTop,
out drawingWidth, out drawingHeight);

// Get the window coordinates in pixels.
referenceWindow.GetWindowRect(out screenLeft, out screenTop,
out screenWidth, out screenHeight);

// Convert the X coordinate by using pixels per inch from the
// width values.
screenX = (int)Math.Round(screenLeft +
((screenWidth / drawingWidth) * (drawingX - drawingLeft)));

// Convert the Y coordinate by using pixels per inch from the
// height values and using a top-left origin (windows
// coordinates) instead of a bottom-left origin (Visio
// coordinates).
screenY = (int)(screenTop +
((screenHeight / drawingHeight) * (drawingTop - drawingY)));
}

catch (Exception err) {
System.Diagnostics.Debug.WriteLine(err.Message);
}

return new System.Drawing.Point(screenX, screenY);
}
}
}
 
D

Dr. Alaa Serry

Thanks Al.
That is extactly what I was looking for. I do appreciate your input and
quick response. Have a great day.
/alaa
 
A

Al Edlund

have a great one,
al

Dr. Alaa Serry said:
Thanks Al.
That is extactly what I was looking for. I do appreciate your input and
quick response. Have a great day.
/alaa
 

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