我无法让文字轮换正常工作,因此请求帮助。 我正在将VB5转换为VB.NET。在VB5中,我使用了createfont API,并希望转换为VB.NET方法。该程序运行2D结构分析。
下面给出了源代码,并给出了相应的输出here
成员描述远不及成员,我尝试了各种变换组合,但似乎没有任何效果。
有人能发现错误吗?
Private Sub PlotMemberDescriptions(ByRef bmp As Bitmap)
Dim g As Graphics = Graphics.FromImage(bmp)
'Set various modes to higher quality
'g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
'g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
'set to current offset values.
'The frame is plotted in traditional X, Y coord system with Y up the page.
'The offsets put 0,0 at mOffsetX from the LHS and mOffsetY from the top
'for plotting of nodes etc.
'g.TranslateTransform(mOffsetX, mOffsetY)
Dim pPlot As New Pen(Color.Black, 0)
Dim fPlot As New System.Drawing.Font("Arial", 8, FontStyle.Regular)
Dim bPlot As New System.Drawing.SolidBrush(Color.Black)
Dim x1, y1 As Single
Dim x2, y2 As Single
Dim xp, yp As Single
'Dim xs, ys As Single
Dim M As CMember
Dim angleRad, angleDeg As Single
Dim dx, dy As Double
Dim sz As SizeF
For Each M In gcolMembers
x1 = M.startNX * mScaleFactor 'member start node x coord, converted to pixel equiv
y1 = M.startNY * mScaleFactor ' y1 is plotted as -y1 to flip Y axis
x2 = M.endNX * mScaleFactor
y2 = M.endNY * mScaleFactor
dx = x2 - x1
dy = y2 - y1
'get member angle in screen system, y down page
If dx = 0 Then 'angledeg is 90, 270
If y2 > y1 Then 'member points up page, +ve Y (frame)
angleRad = Math.PI / 2
Else
angleRad = 1.5 * Math.PI
End If
ElseIf dy = 0 Then
If x2 > x1 Then 'member points +ve X (frame),
angleRad = 0
Else
angleRad = Math.PI
End If
Else
angleRad = System.Math.Atan(dy / dx) 'radians
If dy >= 0 And dx > 0 Then
angleRad = 2 * Math.PI - angleRad
ElseIf dy >= 0 And dx < 0 Then
angleRad = Math.PI - angleRad
ElseIf dy <= 0 And dx < 0 Then
angleRad = Math.PI - angleRad
Else
angleRad = -angleRad
End If
End If
angleDeg = angleRad * 180 / Math.PI
sz = g.MeasureString(M.ID, fPlot)
xp = (x1 + x2 - Math.Abs(Math.Cos(angleRad)) * sz.Width) / 2
yp = (y1 + y2 - Math.Abs(Math.Sin(angleRad)) * sz.Width) / 2
Debug.Print("memb = " & M.ID & " angledeg = " & angleDeg & " xp= " & CInt(xp) & " yp= " & CInt(yp))
RotateAround(g, xp, yp, angleDeg)
g.DrawString(M.ID, fPlot, bPlot, xp, -yp)
Next M
End Sub
'http://www.devx.com/devx/Article/34494/0/page/3
' Rotate around the indicated point.
Private Sub RotateAround(ByVal gr As Graphics, _
ByVal X As Single, ByVal Y As Single, ByVal degrees As Single)
' Translate to center the rectangle at the origin.
gr.TranslateTransform(-X, -Y, Drawing2D.MatrixOrder.Append)
' Rotate.
gr.RotateTransform(degrees, Drawing2D.MatrixOrder.Append)
' Translate the result back to its original position.
gr.TranslateTransform(X, Y, Drawing2D.MatrixOrder.Append)
End Sub