如何在调整圆角矩形大小时保留圆角,就像在 PowerPoint 中的 Adob​​e Illustrator 中一样?

the*_*ker 3 vba microsoft-powerpoint

我正在使用 PowerPoint 创建用户界面模型。

如果您使用带有尖角的常规矩形,这很容易。

使用圆角矩形时很难。

有没有办法在调整圆角矩形的大小时保留圆角矩形的圆角?

目前,如果您调整圆角矩形的大小,圆角会相应地变大/变小。这不是我想要的......我只想调整矩形的宽度和高度,而不改变圆形边框半径。就像在 CSS 中一样。或者就像在 Illustrator 中一样。但是在 PowerPoint 中。

har*_*ymc 8

解决问题需要 VBA 宏。

如果您以前从未使用过 VBA(很幸运),您可以在 Microsoft 文章中了解该主题: PowerPoint 2010 中的 VBA 入门

您将需要以下两个宏:GetShapeRounding 和 SetShapeRounding。两个宏都假定圆角矩形是当前选择的形状。第一个宏以点为单位计算形状的半径大小,第二个宏将选定的形状设置为此半径。

使用宏是通过:

  1. 创建圆角矩形并选择它(或保持选中状态)
  2. 运行第一个宏来计算半径
  3. 调整圆角矩形的大小并使其保持选中状态
  4. 运行第二个宏以将其角设置为计算出的半径

以下是宏:

Dim sngRadius As Single ' Radius size in points

Sub GetShapeRounding()
Dim oSh As Shape
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh
  If .Width < .Height Then
    sngRadius = .Width * .Adjustments(1)
  Else ' .Width >= .Height
    sngRadius = .Height * .Adjustments(1)
  End If
End With
MsgBox sngRadius
Set oSh = Nothing
End Sub

Sub SetShapeRounding()
Dim oSh As Shape
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh
  If .Width < .Height Then
    .Adjustments(1) = sngRadius / .Width
  Else ' .Width >= .Height
    .Adjustments(1) = sngRadius / .Height
  End If
End With
Set oSh = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)

在 PowerPoint 2010 上测试。