自定义椭圆上边缘的边界框切割

发布于 2024-12-02 11:13:45 字数 1725 浏览 2 评论 0原文

我有一个自定义椭圆代码,如下所示。我使用椭圆绘制橡皮筋,并使用两个点设置宽度和高度,代码如下所示。然而,当我绘制椭圆时,边界框正在切割侧面的边缘。我之前使用实际高度和宽度解决了这个问题,但这是在一个独立的应用程序中。当我将它与橡皮筋绘图部分集成时,实际高度和宽度不再起作用,由于某种原因,当我设置宽度和高度时它们不会更新。你知道我该如何修复它,这样边缘就不会被切断吗?

 namespace WpfApplication4
{
    class Ellipse2 : Shape
    {
        EllipseGeometry ellipse;
        public static readonly DependencyProperty TextBoxShapeProperty = DependencyProperty.Register("TextBoxShape", typeof(TextBoxShape), typeof(Ellipse2), new FrameworkPropertyMetadata(null));
        public TextBoxShape TextBoxShape
        {
            get { return (TextBoxShape)GetValue(TextBoxShapeProperty); }
            set { SetValue(TextBoxShapeProperty, value); }
        }
        public Ellipse2()
        {
            ellipse = new EllipseGeometry();

            this.Fill = Brushes.Transparent;
            this.Stroke = Brushes.Gray;
            this.StrokeThickness = 3;

        }
        protected override Geometry DefiningGeometry
        {
            get
            {
                TranslateTransform t = new TranslateTransform(Width / 2, Height / 2);
                ellipse.Transform = t;
                ellipse.RadiusX = this.Width / 2;
                ellipse.RadiusY = this.Height / 2;

                return ellipse;
            }
        }
    }
}

     double width = Math.Abs(initMousePoint.X - currMousePoint.X);
     double height = Math.Abs(initMousePoint.Y - currMousePoint.Y);
     double left = Math.Min(initMousePoint.X, currMousePoint.X);
     double top = Math.Min(initMousePoint.Y, currMousePoint.Y);
     rubberBandShape.Width = width;
     rubberBandShape.Height = height;
     Canvas.SetTop(rubberBandShape, top);
     Canvas.SetLeft(rubberBandShape, left);

I have a custom ellipse code shown bellow. I draw a rubber band using the ellipse setting the width and height using two points, code shown bellow. However when I draw the ellipse the bounding box is cutting of the edges on the sides. I solved this issue before with using actual height and width, but this was in a stand alone application. When I integrated it with the rubber band drawing part, actual height and width don't work anymore, for some reason they don't get updated when I set the width and height. Do you know how can I fix it so that the edges don't get cut off.

 namespace WpfApplication4
{
    class Ellipse2 : Shape
    {
        EllipseGeometry ellipse;
        public static readonly DependencyProperty TextBoxShapeProperty = DependencyProperty.Register("TextBoxShape", typeof(TextBoxShape), typeof(Ellipse2), new FrameworkPropertyMetadata(null));
        public TextBoxShape TextBoxShape
        {
            get { return (TextBoxShape)GetValue(TextBoxShapeProperty); }
            set { SetValue(TextBoxShapeProperty, value); }
        }
        public Ellipse2()
        {
            ellipse = new EllipseGeometry();

            this.Fill = Brushes.Transparent;
            this.Stroke = Brushes.Gray;
            this.StrokeThickness = 3;

        }
        protected override Geometry DefiningGeometry
        {
            get
            {
                TranslateTransform t = new TranslateTransform(Width / 2, Height / 2);
                ellipse.Transform = t;
                ellipse.RadiusX = this.Width / 2;
                ellipse.RadiusY = this.Height / 2;

                return ellipse;
            }
        }
    }
}

     double width = Math.Abs(initMousePoint.X - currMousePoint.X);
     double height = Math.Abs(initMousePoint.Y - currMousePoint.Y);
     double left = Math.Min(initMousePoint.X, currMousePoint.X);
     double top = Math.Min(initMousePoint.Y, currMousePoint.Y);
     rubberBandShape.Width = width;
     rubberBandShape.Height = height;
     Canvas.SetTop(rubberBandShape, top);
     Canvas.SetLeft(rubberBandShape, left);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染柒℉ 2024-12-09 11:13:45

尝试补偿 StrokeThickness,例如

ellipse.RadiusX = (this.Width / 2) - StrokeThickness / 2;
ellipse.RadiusY = (this.Height / 2) - StrokeThickness / 2;

Try to compensate for the StrokeThickness, like

ellipse.RadiusX = (this.Width / 2) - StrokeThickness / 2;
ellipse.RadiusY = (this.Height / 2) - StrokeThickness / 2;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文