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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
'Forme1 pour le dessin
'projet niveau .net framework 3.5
'-reference WindowsBase.dll
Imports System
Imports System.Windows
'ici l'imports qui donne acces aux vecteurs
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Public Class Form1
Dim v As Vector
Dim v1 As Vector
Dim v2 As Vector
Dim b As Bitmap
Dim g As Graphics
Dim courantPoint As PointF
Dim dernierPoint As PointF
Dim Dessine As Boolean = False
Dim listeVecteur As List(Of Vector) = New List(Of Vector)
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Me.DoubleBuffered = True
Me.ResizeRedraw = True
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreeObjetBitmap()
End Sub
Private Sub CreeObjetBitmap()
b = New Bitmap(Me.Width, Me.Height)
Me.BackgroundImage = b
Me.BackgroundImageLayout = ImageLayout.Stretch
g = Graphics.FromImage(Me.BackgroundImage)
g.Clear(Color.White)
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Dim BoutonPresse As MouseButtons = e.Button
If BoutonPresse = Windows.Forms.MouseButtons.Left Then
Dessine = True
courantPoint = e.Location
ElseIf BoutonPresse = Windows.Forms.MouseButtons.Right Then
Dessine = False
End If
'Bouton Gauche >Dessine
If Dessine Then
' verifie si premier click
If dernierPoint.X <> 0 And dernierPoint.Y <> 0 Then
g.DrawLine(New Pen(Color.Black, 2.0), dernierPoint, courantPoint)
Me.Refresh()
'v.x =DX,v.y->DY
v.X = dernierPoint.X - courantPoint.X
v.Y = dernierPoint.Y - courantPoint.Y
listeVecteur.Add(v)
dernierPoint = courantPoint
Else
dernierPoint = courantPoint
End If
Else 'Bouton droit ->Fin du dessin
dernierPoint = New PointF(0, 0)
g.Clear(Color.White)
Dessine = False
End If
End Sub
Private Sub EffaceTout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EffaceTout.Click
'efface tout et recommence
g.Clear(Color.White)
Me.Refresh()
End Sub
Private Sub AfficheAngle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AfficheAngle.Click
Dim forme As frmAfficheAngle = New frmAfficheAngle
'valeur positive (sens anti-horaire)
Dim angle As Double = 0
If listeVecteur.Count <> 0 Then
v1 = listeVecteur(0)
v2 = listeVecteur(1)
angle = Vector.AngleBetween(v1, v2)
forme.TextBox1.Text = "angle(v1,v2) rad :" & angle.ToString & vbCrLf _
& "angle(v1,v2) deg :" & (angle / Math.PI).ToString
End If
forme.ShowDialog()
End Sub
End Class
'forme avec un controle textbox utilise uniquement pour afficher l'angle entre
'le 1er vecteur et le 2eme vecteur
'-ajouter un textbox
Imports System.Windows.Forms
Public Class frmAfficheAngle
End Class |
Partager