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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
| ports System.Runtime.Serialization.Formatters.Soap
Imports System.IO
Imports System.Math
Imports System.Windows.Forms.DataVisualization.Charting
Imports System.Data
Module droite0
Private couleur As Color
Private epaisseur As Integer
Private x1, y1 As Double
Private x2, y2 As Double
Dim ptCourant As Point = New Point(0, 0)
Dim ptPrecedent As Point = New Point(0, 0)
Dim boolOnDessine As Boolean = False
Public macollection As New ArrayList
Public mySeries As Series
Public mySeriesNom As String
Private Function deserialiseSTP() As ArrayList
Dim fileExists As Boolean
fileExists = My.Computer.FileSystem.FileExists("C:\Documents and Settings\a\Mes documents\Visual Studio 2010\Projects\TEST\TEST 18-1\bin\Debug\droite.xml")
Dim macollection As New ArrayList
macollection = Nothing
If fileExists = True Then
Dim FluxdeFichier As Stream = File.OpenRead("C:\Documents and Settings\a\Mes documents\Visual Studio 2010\Projects\TEST\TEST 18-1\bin\Debug\droite.xml")
If FluxdeFichier.Length <> 0 Then
Dim deserializer As New SoapFormatter
macollection = CType(deserializer.Deserialize(FluxdeFichier), ArrayList) FluxdeFichier.Close()
End If
End If
Return macollection
End Function
Private Function indexdeligne(ByVal collectiondedroites) As Integer
Dim i, indexencours, indexlepluseleve As Integer
Dim drcol As objetdroite
indexlepluseleve = 0
If collectiondedroites <> Nothing
For i = 0 To collectiondedroites.count - 1
drcol = collectiondedroites(i)
indexencours = CInt(drcol.mySeriesNom.Replace("Ligne", ""))
If indexencours > indexlepluseleve Then
indexlepluseleve = indexencours
End If
Next
End If
Return indexlepluseleve
End Function
Public Sub dessineunedroite(ByVal contientlescoordonnees As System.Windows.Forms.MouseEventArgs, ByVal graphique As Graphics, ByVal compteur As Integer, ByVal couleur As Color, ByVal epaisseur As Integer)
Dim BoutonPresse As MouseButtons = contientlescoordonnees.Button
If BoutonPresse = Windows.Forms.MouseButtons.Left Then boolOnDessine = True
ptCourant = contientlescoordonnees.Location
End If
If boolOnDessine Then
If ptPrecedent.X <> 0 And ptPrecedent.Y <> 0 Then
ptPrecedent = ptCourant
x2 = ptCourant.X
y2 = ptCourant.Y
x1 = Convert.ToSingle(Form1.Chart1.ChartAreas("ChartArea1").AxisX.PixelPositionToValue(x1))
y1 = Convert.ToSingle(Form1.Chart1.ChartAreas("ChartArea1").AxisY.PixelPositionToValue(y1))
x2 = Convert.ToSingle(Form1.Chart1.ChartAreas("ChartArea1").AxisX.PixelPositionToValue(x2))
y2 = Convert.ToSingle(Form1.Chart1.ChartAreas("ChartArea1").AxisY.PixelPositionToValue(y2))
Dim collectiondedroites As New ArrayList
collectiondedroites = deserialiseSTP()
Dim indexmax As Integer
indexmax = indexdeligne(collectiondedroites)
If indexmax = 0 Then
mySeries = Form1.Chart1.Series.Add("Ligne1")
Else
mySeries = Form1.Chart1.Series.Add("Ligne" + (indexmax + 1).ToString())
End If
mySeries.Points.AddXY(x1, y1)
mySeries.Points.AddXY(x2, y2)
mySeries.ChartType = SeriesChartType
mySeries.Color = couleur
mySeries.BorderWidth = epaisseur
mySeriesNom = mySeries.Name
Dim stockdroite As New objetdroite(mySeriesNom, couleur, epaisseur, x1, y1, x2, y2)
collectiondedroites.Add(stockdroite) 'BUG ICI la collection doit grandir au fur et a mesure que je dessine
' La référence d'objet n'est pas définie à une instance d'un objet*!!
'conseils*:utilisez le mot clé new pour créer une instance dobjet (je pense lavoir fait)
déterminer si lobjet est null avant dappeler la méthode
'je ne sais pas trop mais stockdroite quand je lespionne contient bien mes paramètres
'la variable collectiondedroites contient «*Nothing*» mais justement je voudrais la remplir
pourserialiser(mySeriesNom, couleur, epaisseur, x1, y1, x2, y2, collectiondedroites)
Form1.ToolStripButton1.Checked = False ptPrecedent = New Point(0, 0)
Else
ptPrecedent = ptCourant
x1 = ptCourant.X
y1 = ptCourant.Y
End If
End If
End Sub
Public Sub redessinedroite(ByVal index, ByVal droite, ByVal Chart)
Dim mySeries As Series
mySeries = Chart.Series.Add(droite.mySeriesNom())
mySeries.Points.AddXY(droite.x1, droite.y1)
mySeries.Points.AddXY(droite.x2, droite.y2)
mySeries.ChartType = SeriesChartType.Line
mySeries.Color = droite.couleur
mySeries.BorderWidth = droite.epaisseur
End Sub
Private Sub pourserialiser(ByVal mySeriesNom, ByVal couleur, ByVal epaisseur, ByVal x1, ByVal y1, ByVal x2, ByVal y2, ByVal collectiondedroites)
Dim fileExists As Boolean
fileExists = My.Computer.FileSystem.FileExists("C:\Documents and Settings\a\Mes documents\Visual Studio 2010\Projects\TEST\TEST 18-1\bin\Debug\droite.xml")
If fileExists = True Then
Dim FluxDeFichier As Stream = File.OpenWrite("droite.xml")
Dim Serialiseur As New SoapFormatter
Serialiseur.Serialize(FluxDeFichier, collectiondedroites) '
FluxDeFichier.Close()
Else
Dim FluxDeFichier As FileStream = File.Create("droite.xml")
Dim Serialiseur As New SoapFormatter
Serialiseur.Serialize(FluxDeFichier, collectiondedroites)
FluxDeFichier.Close()
End If
End Sub
End Module
Imports System.Windows.Forms.DataVisualization.Charting
<Serializable()>
Public Class objetdroite
Public mySeriesNom As String
Public couleur As Color
Public epaisseur As Integer
Public x1, y1 As Integer
Public x2, y2 As Integer
Public Sub New(ByVal nomserie As String, ByVal couleurparam As Color, Optional ByVal epaisseurparam As Integer = 0, Optional ByVal x1param As Integer = 0, Optional ByVal y1param As Integer = 0, Optional ByVal x2param As Integer = 1, Optional ByVal y2param As Integer = 1)
x1 = x1param
y1 = y1param
x2 = x2param
y2 = y2param
couleur = couleurparam
epaisseur = epaisseurparam
mySeriesNom = nomserie
End Sub
Public Function IsAt(ByVal x As Integer, ByVal y As Integer) As Boolean
Return PointNearSegment(x, y, x1, y1, x2, y2)
End Function
Private Function IsSelected() As Boolean
Return 0
End Function
End Class |
Partager