如何围绕自定义路径形状绘制矩形 [英] How to Draw a Rectangle around a custom Path shape

查看:128
本文介绍了如何围绕自定义路径形状绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

谁能帮我将自定义路径形状围成一个矩形.

我有一个画布.单击鼠标在画布上将点存储在列表中.
使用点列表,iam可以在画布上绘制自定义路径形状.

我想做的是绘制路径形状后,当我单击路径形状时,我想在形状周围绘制一个矩形作为边界.自定义路径形状应包含在矩形中.

我想将装饰物添加到矩形边界并调整路径形状的大小.

我这样尝试过,但矩形边界比路径形状大得多

Hello,

Can any one help me to enclose the custom path shape in a rectangle.

I have a canvas.for each mouse click on the canvas store the points in a list.
With the point list iam able to draw the custom path shape on the canvas.

what iam trying to do is after drawing a path shape, when i click on the path shape i want to draw a rectangle around the shape as a boundary. The custom path shape should be enclosed in the rectangle.

i want to add adorners to the rectangle boundary and resize the path shape.

i tried like this but the rectangle boundary is much bigger than the path shape

// code in the adorner class
 Path rectouline=new Path();
rectouline.Stroke = Brushes.Blue; rectouline.StrokeThickness = 1;

protected override Size ArrangeOverride(Size finalSize)
{
   // rectangle around the path shape 
    Rect boundaryrect= new Rect(finalSize);
    rectouline.Data = new RectangleGeometry(boundaryrect);
    rectouline.Arrange(boundaryrect);

return finalSize;
}




可以为您提供帮助.

谢谢,




can help will be much appreciated.

Thanks,

推荐答案

使用内置函数:

Use the built in functions:

GraphicsPath path;
RectangleF rect;

path = new GraphicsPath();
path.AddLine(100, 100, 100, 200);
path.AddLine(100, 200, 200, 200);
path.AddLine(200, 200, 100, 100);
rect = path.GetBounds();


这篇关于如何围绕自定义路径形状绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆