Master MyMaster = MyStencil.Masters["Navigation"];
Shape MyShape = MyPage.Drop(MyMaster, PageRight / 2.0, PageTop / 2.0);
MyShape.Text = "Some text";
double ShapeLeft, ShapeBottom, ShapeRight, ShapeTop;
MyShape.BoundingBox((short)VisBoundingBoxArgs.visBBoxUprightText,
out ShapeLeft, out ShapeBottom, out ShapeRight, out ShapeTop);创建文本形状后,将计算其边界框以生成页面的其他组件。这在早期版本的Visio中工作得很好,但在Visio 2016中就不行了。
Visio 2010和Visio 2013中的文本形状边框为:
ShapeLeft = 5.48
ShapeBottom = 4.05
ShapeRight = 6.20
ShapeTop = 4.21Visio 2016中的形状边界框为:
ShapeLeft = 0.0
ShapeBottom = 0.0
ShapeRight = -1.0
ShapeTop = -1.0谢谢,
销售
发布于 2016-12-23 15:36:15
我也可以重现这一点,但有一些细节表明BoundingBox()在visio16中工作得很好,
Shape.BoundingBox()将"((short)Visio.VisBoundingBoxArgs.visBBoxUprightText“作为第一个参数,该参数在这里提到,用于获取文本包围的矩形的边界框。下面是catch,Shape.BoundingBox()方法检查Shape.type(),在本例中,该方法以矩形的形式返回,标志表示获取文本的边界框,该文本在失败的情况下结束,从而得到观察到的输出。
上面的陈述可以用这里给出的信息来验证,https://msdn.microsoft.com/en-us/library/office/ff766755.aspx
“如果BoundingBox方法返回错误,或者要求它返回包含零个形状的矩形,则返回的矩形为{ left: 0,bottom: 0,right:-1,top:-1 };否则,返回的矩形left小于或等于(<=) right,且bottom小于或等于(<=) top。返回的数字以内部单位(英寸)表示。”
此外,为了验证BoundingBox()返回的值是否正确,我们可以尝试使用标志"visBBoxUprightWH“,它给出了我们正在查询边界框的矩形的确切边界框。(代码如下)
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Visio::Application application = Globals.ThisAddIn.Application;
Visio::Page page = application.ActivePage;
Visio::Document basicStencil = application.Documents.OpenEx("basic_u.vssx", (short)(Visio.VisOpenSaveArgs.visOpenRO | Visio.VisOpenSaveArgs.visOpenHidden));
var master = basicStencil.Masters.ItemU["Rectangle"];
double pinX = 5.5;
double pinY = 5.5;
double height = 2.0;
double width = 2.0;
Visio::Shape shape = page.Drop(master, pinX, pinY);
String text = "I am here";
shape.Text = text;
Visio.Cell cell = shape.get_CellsU("Height");
cell.ResultIUForce = height;
cell = shape.get_CellsU("Width");
cell.ResultIUForce = width;
double Left = 0.0;
double Right = 0.0;
double Bottom = 0.0;
double Top = 0.0;
shape.BoundingBox((short)Visio.VisBoundingBoxArgs.visBBoxDrawingCoords, out Left, out Bottom, out Right, out Top);
Console.WriteLine(Left); //4.5
Console.WriteLine(Right); //6.5
Console.WriteLine(Bottom); //6.5
Console.WriteLine(Top); //4.5
}visio首先在内部获取实际矩形内的文本的临时矩形,然后在查询BoundingBox()时使用标志"visBBoxUprightText“调用此临时矩形形状上的BoundingBox方法。
https://stackoverflow.com/questions/39756685
复制相似问题