如何在 excel VBA 中的窗口边缘绘制半圆



我正在尝试使用msoShapeArc和AddShape绘制一个半圆。半圆需要接触页面顶部。 为此,我将 y 值设置为 -radius。 这在使用图形的 C# 中工作,但 excel 忽略负坐标并将形状降低到零。

    Sub DrawArrowArc(CentX As Single, CentY As Single, radius As Single, Ang1 As Single, Ang2 As Single)
       Dim Arc        As Shape
       'Draw 90-degree arc with radius = Radius and center at (CenterX,CenterY)
       Set Arc = ActiveSheet.Shapes.AddShape(msoShapeArc, CentX, CentY - radius, radius, radius)
       'Add arrowhead on clockwise end
       Arc.Line.EndArrowheadStyle = msoArrowheadNone
       'adjust arrow to start at Ang1 and end at Ang2
       '(measured clockwise positive from vertical)
       Arc.Adjustments.Item(1) = 90 - Ang1
       Arc.Adjustments.Item(2) = 90 - Ang2
    End Sub
DrawArrowArc 0, -100, 100, 90, -90

我对实现这一目标的不同方式持开放态度。 圆圈不需要像形状那样可选或可编辑,它的图片就可以了。

它确实需要即时绘制。

它必须是一个完美的半圆。 挤压它是不可接受的。

那你怎么看?

Sub DrawArrowArc(CentX As Single, CentY As Single, radius As Single, Ang1 As 
    Single, Ang2 As Single)
    Dim Arc As Shape    ' 
    'Draw 90-degree arc with radius = Radius and center at (CenterX,CenterY)
    Set Arc = ActiveSheet.Shapes.AddShape(msoShapeArc, CentX, CentY - 
    radius,radius, radius)
    'Add arrowhead on clockwise end
    Arc.Line.EndArrowheadStyle = msoArrowheadNone
    'adjust arrow to start at Ang1 and end at Ang2
    '(measured clockwise positive from vertical)
    Arc.Adjustments.Item(1) = 90 - Ang1
    Arc.Adjustments.Item(2) = 90 - Ang2
    Arc.ThreeD.RotationY = 180
End Sub
Sub CallDrawArrowArc()
    DrawArrowArc 0, -100, 100, -90, 90
End Sub

最新更新