Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303

    Tracciare una linea

    con questo listato riesco a disegnare a mano libera, ma se invece volessi tracciare delle linee rette di cosa devo tenere conto?

    codice:
    Private Declare Function ExtFloodFill Lib "Gdi32" (ByVal hdc As Long, ByVal _
    X As Long, ByVal Y As Long, ByVal crColor As Long, ByVal wFillType As Long) As _
    Long
    Dim X1, Y1 As Single
    Dim Disegna As Boolean
    
    Private Sub Form_Load()
    Picture1.DrawWidth = 3
    Picture1.FillStyle = vbSolid
    Picture1.ScaleMode = 3
    Picture1.FillColor = vbBlack
    End Sub
    
    Private Sub Form_Resize()
    Picture1.Width = Me.Width
    Picture1.Height = Me.Height
    End Sub
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X _
    As Single, Y As Single)
    Disegna = 1
    If Button = vbLeftButton Then
    X1 = X
    Y1 = Y
    End If
    If Button = vbRightButton Then
    Picture1.FillColor = RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
    ExtFloodFill Picture1.hdc, X, Y, RGB(0, 0, 0), FLOODFILLBORDER
    End If
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X _
    As Single, Y As Single)
    
    Label1.Caption = X
    Label2.Caption = Y
    
    If Button = vbLeftButton Then
    If Disegna = True Then
    Picture1.Line (X1, Y1)-(X, Y)
    X1 = X
    Y1 = Y
    End If
    End If
    End Sub
    
    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X _
    As Single, Y As Single)
    Disegna = False
    End Sub

  2. #2
    codice:
    Option Explicit
    
    Private Declare Function ExtFloodFill Lib "Gdi32" (ByVal hdc As Long, ByVal _
    X As Long, ByVal Y As Long, ByVal crColor As Long, ByVal wFillType As Long) As _
    Long
    Dim X1, Y1 As Single
    Dim Disegna As Boolean
    
    Private Sub Form_Load()
    Picture1.DrawWidth = 3
    Picture1.FillStyle = vbSolid
    Picture1.ScaleMode = 3
    Picture1.FillColor = vbBlack
    End Sub
    
    Private Sub Form_Resize()
    Picture1.Width = Me.Width
    Picture1.Height = Me.Height
    End Sub
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X _
    As Single, Y As Single)
    Disegna = 1
    If Button = vbLeftButton Then
    X1 = X
    Y1 = Y
    End If
    If Button = vbRightButton Then
    Picture1.FillColor = RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
    ExtFloodFill Picture1.hdc, X, Y, RGB(0, 0, 0), 1 'FLOODFILLBORDER
    End If
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X _
    As Single, Y As Single)
    
    Label1.Caption = X
    Label2.Caption = Y
    
    If Button = vbLeftButton Then
    
    'If Disegna = True Then
    'Picture1.Line (X1, Y1)-(X, Y)
    'X1 = X
    'Y1 = Y
    'End If
    
    End If
    End Sub
    
    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X _
    As Single, Y As Single)
    If Disegna = True Then
    Picture1.Line (X1, Y1)-(X, Y)
    X1 = X
    Y1 = Y
    End If
    
    Disegna = False
    End Sub
    in poche parole non devi + disegnare quando muovi il mouse, ma quando lasci il tasto. Devi solo spostare il codice ...
    codice:
    If Disegna = True Then
    Picture1.Line (X1, Y1)-(X, Y)
    X1 = X
    Y1 = Y
    End If
    ... in MouseUp

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.