Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15
  1. #1

    [VB6]Spostare oggetti in una maschera

    Salve a tutti, ho urgenza di sapere come si spostano degli oggetti in una maschera,
    ad esempio se inserisco un'immagine in un maschera vorrei che l'utente puà spostarla dove vuole.E' possibile una cosa del genere??

    Grazie a tutti in anticipo!!!



    Chi mi aiuta in questa cosa è un grande, disposta retribuzione se qualcuno ha qualche esempio già fatto!!
    http://www.generationweb.it <--- web site

  2. #2
    Ecco del codice che ho scritto che ti verrà certamente in aiuto:
    codice:
    Private m_movingControl As Control
    Private vShift As Single
    Private hShift As Single
    Private Property Set movingControl(vNewValue As Control)
    Set m_movingControl = vNewValue
    If vNewValue Is Nothing Then
        Screen.MousePointer = vbDefault
    Else
        Screen.MousePointer = vbSizeAll
    End If
    End Property
    Private Property Get movingControl() As Control
    Set movingControl = m_movingControl
    End Property
    Private Sub HandleMouseDown(Sender As Object, ByVal X As Single, ByVal Y As Single, Optional Moveable As Boolean = True)
        If movingControl Is Nothing And Moveable Then
            vShift = Y
            hShift = X
            Set movingControl = Sender
        Else
            If TypeOf Sender Is Control Then
                X = Sender.Left + X
                Y = Sender.Top + Y
            ElseIf TypeOf Sender Is Form Then
            Else
                Err.Raise 5
            End If
            If Not (movingControl Is Nothing) Then
                movingControl.Move X - hShift, Y - vShift
                Set movingControl = Nothing
            End If
        End If
    End Sub
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        HandleMouseDown Me, X, Y, False
    End Sub
    Aggiungendo tale codice all'inizio del tuo form puoi poi utilizzarlo per gestire gli spostamenti dei vari controlli; per far sì che un controllo possa essere spostato aggiungi al suo evento MouseDown il seguente codice:
    codice:
    HandleMouseDown <nomecontrollo>, X, Y
    dove <nomecontrollo> è il nome di tale controllo; per far sì che su un controllo se ne possa spostare un altro aggiungi il seguente codice al suo evento MouseDown:
    codice:
    HandleMouseDown <nomecontrollo>, X, Y, False
    .
    Di seguito un esempio completo, in cui vi sono due PictureBox (PictureBox1 e PictureBox2) che possono essere spostate in giro per il form:
    codice:
    Option Explicit
    Private m_movingControl As Control
    Private vShift As Single
    Private hShift As Single
    Private Property Set movingControl(vNewValue As Control)
    Set m_movingControl = vNewValue
    If vNewValue Is Nothing Then
        Screen.MousePointer = vbDefault
    Else
        Screen.MousePointer = vbSizeAll
    End If
    End Property
    Private Property Get movingControl() As Control
    Set movingControl = m_movingControl
    End Property
    Private Sub HandleMouseDown(Sender As Object, ByVal X As Single, ByVal Y As Single, Optional Moveable As Boolean = True)
        If movingControl Is Nothing And Moveable Then
            vShift = Y
            hShift = X
            Set movingControl = Sender
        Else
            If TypeOf Sender Is Control Then
                X = Sender.Left + X
                Y = Sender.Top + Y
            ElseIf TypeOf Sender Is Form Then
            Else
                Err.Raise 5
            End If
            If Not (movingControl Is Nothing) Then
                movingControl.Move X - hShift, Y - vShift
                Set movingControl = Nothing
            End If
        End If
    End Sub
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        HandleMouseDown Me, X, Y, False
    End Sub
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        HandleMouseDown Picture1, X, Y
    End Sub
    
    Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        HandleMouseDown Picture2, X, Y
    End Sub
    .
    Per spostare i controlli "abilitati" allo spostamento basta cliccarci sopra (il cursore cambierà forma) e quindi cliccare in un punto del form o di un controllo "abilitato" allo spostamento o alla ricezione di spostamenti.
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    PERFETTO NON HO PAROLE!!!!!!!!!!!
    SEI UN MITO
    GRAZIEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    http://www.generationweb.it <--- web site

  4. #4
    Ah ragazzi un'ultima cosa, questo codice è poccibile utilizzarlo anche in Microsoft access cioè in VBA???

    Grazie ancora!!
    http://www.generationweb.it <--- web site

  5. #5
    Credo di sì con qualche adattamento...
    Amaro C++, il gusto pieno dell'undefined behavior.

  6. #6
    eh è quello che nn riesco a fare

    help!
    http://www.generationweb.it <--- web site

  7. #7
    Basta modificare le seguenti linee:
    codice:
            ElseIf TypeOf Sender Is Form Then
    diventa
            ElseIf TypeOf Sender Is UserForm Then
    ---
        Screen.MousePointer = vbDefault
    diventa
        Me.MousePointer = fmMousePointerDefault
    ---
        Screen.MousePointer = vbSizeAll
    diventa
        Me.MousePointer = fmMousePointerSizeAll
    .
    Bisogna inoltre modificare le firme dei gestori di eventi, ma per quello basta far creare a VBA i gestori eventi automaticamente; l'unico cambiamento in questo senso comunque se non sbaglio è la convenzione di passaggio dei parametri (tutti i parametri sono ByVal):
    codice:
    Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    .
    Amaro C++, il gusto pieno dell'undefined behavior.

  8. #8
    Allora ho effettuato le modifche da te riportate ma nn mi funziona, mi dice:

    L'espressione su caricamento immessa come impostazione della proprietà di evento ha provocato il seguente errore: La dichiarazione della routine non corrisponde alla descrizione dell'evento o della routine con lo stesso nome.

    il codice che ho usato su di una foto chiamata "img" è il seguente (in VBA)

    Option Explicit
    Private m_movingControl As Control
    Private vShift As Single
    Private hShift As Single
    Private Property Set movingControl(vNewValue As Control)
    Set m_movingControl = vNewValue
    If vNewValue Is Nothing Then
    Me.MousePointer = fmMousePointerDefault
    Else
    Me.MousePointer = fmMousePointerSizeAll
    End If
    End Property
    Private Property Get movingControl() As Control
    Set movingControl = m_movingControl
    End Property
    Private Sub HandleMouseDown(Sender As Object, ByVal X As Single, ByVal Y As Single, Optional Moveable As Boolean = True)
    If movingControl Is Nothing And Moveable Then
    vShift = Y
    hShift = X
    Set movingControl = Sender
    Else
    If TypeOf Sender Is Control Then
    X = Sender.Left + X
    Y = Sender.Top + Y
    ElseIf TypeOf Sender Is UserForm Then
    Else
    Err.Raise 5
    End If
    If Not (movingControl Is Nothing) Then
    movingControl.Move X - hShift, Y - vShift
    Set movingControl = Nothing
    End If
    End If
    End Sub

    Private Sub img_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    HandleMouseDown img, X, Y
    End Sub

    Private Sub Form_MouseDown(ByVal Button As Integer, Shift As Integer, X As Single, Y As Single)
    HandleMouseDown Me, X, Y, False
    End Sub
    http://www.generationweb.it <--- web site

  9. #9
    Come detto sopra, devi modificare le firme dei gestori di eventi:
    codice:
    Private Sub Form_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Amaro C++, il gusto pieno dell'undefined behavior.

  10. #10
    Niente sempre il solito errore
    http://www.generationweb.it <--- web site

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.