Ciao a tutti ho un piccolo problema...Devo disegnare delle linee dinamicamente, cioè clicco una prima volta e fisso il primo punto, poi muovendomi devo vedere la linea muoversi e poi con un secodno click fisso il secondo punto della linea...
Sono da poco passato a vb.net...In vb6 tutto questo lo facevo con il seguente codice:
Ho provato a riadattarlo in vb.net in questo modo ma il risultato è pessimo...codice:Dim oldX As Single, oldY As Single 'Array Linee Dim arrX1(1000) As Single Dim arrX2(1000) As Single Dim arrY1(1000) As Single Dim arrY2(1000) As Single Dim iNumLinee As Integer Private Sub Form_Load() oldX = -1: oldY = -1 End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If oldX <> -1 Then Picture2.PaintPicture Picture1.Image, 0, 0 Else 'Aggiunge le coordinate della linea negli array delle linee arrX1(iNumLinee) = oldX arrX2(iNumLinee) = X arrY1(iNumLinee) = oldY arrY2(iNumLinee) = Y iNumLinee = iNumLinee + 1 End If oldX = X oldY = Y End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If oldX = -1 Then Exit Sub Picture1.PaintPicture Picture2.Image, 0, 0 Picture1.Line (oldX, oldY)-(X, Y), RGB(0, 0, 0) End Sub
codice:Public Class Form1 Dim oldX As Single, oldY As Single 'Array Linee Dim arrX1(1000) As Single Dim arrX2(1000) As Single Dim arrY1(1000) As Single Dim arrY2(1000) As Single Dim iNumLinee As Integer Dim bm As Bitmap Private Sub Picture1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picture1.MouseDown If oldX <> -1 Then bm = New Bitmap(Picture1.Size.Width, Picture1.Size.Height, Picture1.CreateGraphics()) Else 'Aggiunge le coordinate della linea negli array delle linee arrX1(iNumLinee) = oldX arrX2(iNumLinee) = e.X arrY1(iNumLinee) = oldY arrY2(iNumLinee) = e.Y iNumLinee = iNumLinee + 1 End If oldX = e.X oldY = e.Y End Sub Private Sub Picture1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picture1.MouseMove If oldX = -1 Then Exit Sub Picture1.Image = (bm) Picture1.CreateGraphics.DrawLine(Pens.Black, oldX, oldY, e.X, e.Y) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load oldX = -1 : oldY = -1 End Sub End Class
Qualcuno saprebbe aiutarmi?....Grazie mille a tutti...![]()

Rispondi quotando
