18277132841 发表于 2024-5-7 14:28

vb.net怎么获取多行文字包围盒

用vb.net怎么获取多行文字包围盒,只是显示的文字部分,不包含编辑框范围的。

tiancao100 发表于 2024-5-7 17:11

''' <summary>
      ''' Gets the WCS points of the mtext bounding box.
      ''' </summary>
      ''' <param name="mtext">Instance of MText the method applies to.</param>
      ''' <returns>The bounding box points in counterclockwise sense.</returns>
      Public Shared Function GetMTextBoxCorners(mtext As MText) As Point3d()
            Dim width As Double = mtext.ActualWidth
            Dim height As Double = mtext.ActualHeight
            Dim point1 As Point3d, point2 As Point3d
            Select Case mtext.Attachment
                Case AttachmentPoint.TopLeft
                  point1 = New Point3d(0.0, -height, 0.0)
                  point2 = New Point3d(width, 0.0, 0.0)
                  Exit Select
                Case AttachmentPoint.TopCenter
                  point1 = New Point3d(-width * 0.5, -height, 0.0)
                  point2 = New Point3d(width * 0.5, 0.0, 0.0)
                  Exit Select
                Case AttachmentPoint.TopRight
                  point1 = New Point3d(-width, -height, 0.0)
                  point2 = New Point3d(0.0, 0.0, 0.0)
                  Exit Select
                Case AttachmentPoint.MiddleLeft
                  point1 = New Point3d(0.0, -height * 0.5, 0.0)
                  point2 = New Point3d(width, height * 0.5, 0.0)
                  Exit Select
                Case AttachmentPoint.MiddleCenter
                  point1 = New Point3d(-width * 0.5, -height * 0.5, 0.0)
                  point2 = New Point3d(width * 0.5, height * 0.5, 0.0)
                  Exit Select
                Case AttachmentPoint.MiddleRight
                  point1 = New Point3d(-width, -height * 0.5, 0.0)
                  point2 = New Point3d(0.0, height * 0.5, 0.0)
                  Exit Select
                Case AttachmentPoint.BottomLeft
                  point1 = New Point3d(0.0, 0.0, 0.0)
                  point2 = New Point3d(width, height, 0.0)
                  Exit Select
                Case AttachmentPoint.BottomCenter
                  point1 = New Point3d(-width * 0.5, 0.0, 0.0)
                  point2 = New Point3d(width * 0.5, height, 0.0)
                  Exit Select
                Case AttachmentPoint.BottomRight
                  point1 = New Point3d(-width, 0.0, 0.0)
                  point2 = New Point3d(0.0, height, 0.0)
                  Exit Select
            End Select
            Dim xform As Matrix3d = Matrix3d.Displacement(mtext.Location.GetAsVector()) * Matrix3d.Rotation(mtext.Rotation, mtext.Normal, Point3d.Origin) * Matrix3d.PlaneToWorld(New Plane(Point3d.Origin, mtext.Normal))
            Return New Point3d() {point1.TransformBy(xform), New Point3d(point2.X, point1.Y, 0.0).TransformBy(xform), point2.TransformBy(xform), New Point3d(point1.X, point2.Y, 0.0).TransformBy(xform)}
      End Function

18277132841 发表于 2024-5-8 08:26

tiancao100 发表于 2024-5-7 17:11


感谢感谢
页: [1]
查看完整版本: vb.net怎么获取多行文字包围盒