1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
Imports System.Drawing.Drawing2D
Public Class Pivot
Inherits UserControl
'ce rectangle sert à faire comprendre le principe
Dim rectBorder As Rectangle
Dim penBorder As New Pen(Brushes.Red, 4)
'le bitmap possede un rectangle englobant (0,0,width,height)
Dim widthBmp As Integer
Dim heigthBmp As Integer
'on la rescale pour ne pas depasser les limites du control
'lorsque elle pivote
Dim factorScale As Integer = 1.95
'centre du control
Dim centerCtrl As Point
'origine du bitmap (doit etre fixe par rapport au centre du control)
Dim originBmp As Point
Dim imagetwo As Bitmap
Dim angle As Integer
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
Private Sub Pivot1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
getimage()
End Sub
Private Sub getimage()
imagetwo = New Bitmap(My.Resources.floral, Me.Width / factorScale, Me.Height / factorScale)
imagetwo.MakeTransparent(Color.Black)
'centre du control
centerCtrl = New Point(Me.Width / 2, Me.Height / 2)
widthBmp = imagetwo.Width
heigthBmp = imagetwo.Height
originBmp = New Point(centerCtrl.X - widthBmp / 2, centerCtrl.Y - heigthBmp / 2)
rectBorder = New Rectangle(originBmp.X, originBmp.Y, widthBmp, heigthBmp)
gameloop.Start()
End Sub
Private Sub Pivot1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim m As Matrix = New Matrix
m.RotateAt(angle, centerCtrl)
e.Graphics.Transform = m
e.Graphics.DrawImage(imagetwo, originBmp.X, originBmp.Y)
e.Graphics.DrawRectangle(penBorder, rectBorder)
End Sub
Private Sub gameloop_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gameloop.Tick
angle += 15
Me.Refresh()
End Sub
Private Sub Pivot_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
getimage()
End Sub
End Class |