我要想要的效果如下图,代码我也写了,就是出不来,请求高手帮忙解决
开发环境:VS2013
Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim pa As New Panel
pa.BackColor = Color.Silver
pa.Location = New Point(200, 200)
pa.Width = 120
pa.Height = 25
Me.Controls.Add(pa)
Dim g As Graphics = pa.CreateGraphics
Dim ft As New Font("arial", 12, FontStyle.Bold)
Dim rote As Integer = 90
Dim rotatePoint As New PointF(pa.Height / 2, pa.Width / 2) '设定旋转的中心点
Dim strChar As String = "小儿咳嗽药水"
Dim size As SizeF = g.MeasureString(strChar, ft)
Dim myMatrix As New Matrix
myMatrix.RotateAt(rote, rotatePoint, MatrixOrder.Append)
g.Transform = myMatrix
g.DrawString(strChar, ft, New SolidBrush(Color.Red), rotatePoint.X - size.Width, rotatePoint.Y - size.Height)
End Sub
End Class
------解决思路----------------------
panel是个容器,它本身是不能转的
你可以转文字
------解决思路----------------------
Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim pa As New Panel
pa.BackColor = Color.Silver
pa.Location = New Point(200, 200)
pa.Width = 25 '<- 坐标变换影响的是绘图输出,控件本身不会旋转,'
pa.Height = 120 ' 匹配输出方式应该是竖条状而不是横条状。'
Me.Controls.Add(pa)
Dim g As Graphics = pa.CreateGraphics
Dim ft As New Font("arial", 12, FontStyle.Bold)
Dim rote As Integer = 90
Dim rotatePoint As New PointF(pa.Width / 2, pa.Height / 2) '<- 用原始坐标,而不是变换后的坐标'
Dim strChar As String = "小儿咳嗽药水"
Dim size As SizeF = g.MeasureString(strChar, ft)
g.TranslateTransform(rotatePoint.X, rotatePoint.Y) '平移'
g.RotateTransform(rote) '旋转'
' 绘图倒是要用变换后的坐标,这时原点在中心、X轴指向下、Y轴指向右。'
' 和 rotatePoint 没有关系了。'
g.DrawString(strChar, ft, New SolidBrush(Color.Red), -size.Width / 2, -size.Height / 2)
End Sub
End Class