考虑以下代码:
Ellipse myCircle = new Ellipse();
myCircle.Width = 400;
myCircle.Height = 400;
myCircle.Stroke = Brushes.PeachPuff;
myCircle.StrokeThickness = 25;
myCircle.ToolTip = "Bold Circle";
Canvas.SetTop(myCircle, 0);
Canvas.SetLeft(myCircle, 0);
canvas.Children.Add(myCircle);
Ellipse myCircle2 = new Ellipse();
myCircle2.Width = 400;
myCircle2.Height = 400;
myCircle2.Stroke = Brushes.Black;
myCircle2.StrokeThickness = 1;
Canvas.SetTop(myCircle2, 0);
Canvas.SetLeft(myCircle2, 0);
canvas.Children.Add(myCircle2);
我看到myCircle2位于myCircle的边缘。 如何定义myCircle的笔触样式,使myCircle2位于myCircle的中间?
谢谢!
答案 0 :(得分:0)
有几种方法:一种是这种方式(在XAML中)
<Canvas>
<Ellipse Width="400" Height="400" Stroke="PeachPuff" StrokeThickness="25" />
<Ellipse Width="375" Height="375" Stroke="Black" StrokeThickness="1" Margin="12.5 12.5 0 0" />
答案 1 :(得分:0)
尝试将此视为一般情况:
int diameter = 400;
int thickness = 25;
Ellipse myCircle = new Ellipse();
myCircle.StrokeThickness = thickness;
myCircle.Width = diameter + thickness;
myCircle.Height = diameter + thickness;
myCircle.Stroke = Brushes.PeachPuff;
myCircle.ToolTip = "Bold Circle";
Canvas.SetTop(myCircle, -thickness/2);
Canvas.SetLeft(myCircle, -thickness / 2);
canvas.Children.Add(myCircle);
Ellipse myCircle2 = new Ellipse();
myCircle2.Width = diameter;
myCircle2.Height = diameter;
myCircle2.Stroke = Brushes.Black;
myCircle2.StrokeThickness = 1;
Canvas.SetTop(myCircle2, 0);
Canvas.SetLeft(myCircle2, 0);
canvas.Children.Add(myCircle2);
此处的调整是通过调整宽度,正方向的高度以及将负方向的顶部和左侧调整为一半来调整粗体圆的厚度。