How to rotate a RectangleShape in VB.net?

2019-09-10 05:49发布

问题:

Is it possible to rotate a rectangle shape in VB.net? Code to my rectangle shape is this

baseDice.Parent = shapeContainer
baseDice.CornerRadius = 5
baseDice.Height = 50
baseDice.Width = 50
baseDice.BackColor = Color.Blue
baseDice.BackStyle = BackStyle.Opaque
baseDice.Left = 50
baseDice.Top = 50
baseDice.Name = "baseDice"

baseDice is an object of Microsoft.VisualBasic.PowerPacks.RecntangleShape

回答1:

Use the VB Class Matrix, here's an example

Dim myPen As New Pen(Color.Blue, 1)
Dim myPen2 As New Pen(Color.Red, 1)
e.Graphics.DrawRectangle(myPen, 150, 50, 200, 100)
Dim myMatrix As New Matrix()
myMatrix.Rotate(45, MatrixOrder.Append)
e.Graphics.Transform = myMatrix
e.Graphics.DrawRectangle(myPen2, 150, 50, 200, 100)

In the Matrix.Rotate you give it the angle and what the type of transform is (you can use Append to constantly rotate by an angle)

e is of PaintEventArgs type