|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
[VB.NET] DragDrop
Allora, forse sono io che sono rincoglionito, ma sto impazzendo per fare un cavolo di dragdrop di file nel form. Alla fine preso dalla disperazione ho provato con un bel copia-incolla... ma non va! Questo l'esempio che ho copiato da MSDN:
Aprite un nuovo progetto windows e schiaffateci questo codice: Codice:
Public Class Form1 Private picture As Image Private pictureLocation As Point Public Sub New() ' Enable drag-and-drop operations. InitializeComponent() Me.AllowDrop = True End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) MyBase.OnPaint(e) ' If there is an image and it has a location, ' paint it when the Form is repainted. If (Me.picture IsNot Nothing) And _ Not (Me.pictureLocation.Equals(Point.Empty)) Then e.Graphics.DrawImage(Me.picture, Me.pictureLocation) End If End Sub Private Sub Form1_DragDrop(ByVal sender As Object, _ ByVal e As DragEventArgs) Handles MyBase.DragDrop ' Handle FileDrop data. If e.Data.GetDataPresent(DataFormats.FileDrop) Then ' Assign the file names to a string array, in ' case the user has selected multiple files. Dim files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String()) Try ' Assign the first image to the 'picture' variable. Me.picture = Image.FromFile(files(0)) ' Set the picture location equal to the drop point. Me.pictureLocation = Me.PointToClient(New Point(e.X, e.Y)) Catch ex As Exception MessageBox.Show(ex.Message) Return End Try End If ' Handle Bitmap data. If e.Data.GetDataPresent(DataFormats.Bitmap) Then Try ' Create an Image and assign it to the picture variable. Me.picture = CType(e.Data.GetData(DataFormats.Bitmap), Image) ' Set the picture location equal to the drop point. Me.pictureLocation = Me.PointToClient(New Point(e.X, e.Y)) Catch ex As Exception MessageBox.Show(ex.Message) Return End Try End If ' Force the form to be redrawn with the image. Me.Invalidate() End Sub Private Sub Form1_DragEnter(ByVal sender As Object, _ ByVal e As DragEventArgs) Handles MyBase.DragEnter ' If the data is a file or a bitmap, display the copy cursor. If e.Data.GetDataPresent(DataFormats.Bitmap) _ Or e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub End Class Praticamente si dovrebbe essere in grado di trascinare un file immagine sul form e questa dovrebbe diventare lo sfondo della stessa. |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Up
|
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Up.
Qualcuno potrebbe provare il codice e dirmi se funziona? Perché inizio a pensare che il problema non sia quello... Cmq la versione che uso è la 2005 |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Io l'ho provato su VB 2008 con un .bmp, .jpg, .gif e direi decisamente che funziona.
Inoltre sulla parte destra della pagina che hai linkato è espressamente detto che : This page is specific to Microsoft Visual Studio 2008/.NET Framework 3.5. Other versions are also available for the following: Microsoft Visual Studio 2003/.NET Framework 1.1 Microsoft Visual Studio 2005/.NET Framework 2.0 .NET Framework 3.0 ![]() |
![]() |
![]() |
![]() |
#5 | |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Quote:
Che svista colossale! ![]() |
|
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
No, non va neanche così. Mi sa che devo reinstallare tutto perché c'è qualcosa che non va.
Grazie dell'aiuto EDIT: Ho reinstallato sia VB che il framework (3.5) ma non va... Qualche idea? Ultima modifica di wingman87 : 06-10-2008 alle 22:28. |
![]() |
![]() |
![]() |
#7 | |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Nota : se usi VB2005, puoi aver anche installato FW3.5, ma non potrai mai creare applicazioni FW3.5. Potrai solo eseguirle. In ogni caso penso sia proprio un problema della tua installazione di VS... Ma non saprei proprio cosa possa essere. Se puoi posta il msg d'errore del Fw... |
|
![]() |
![]() |
![]() |
#8 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Il fatto è che non da nessun errore... Semplicemente quando provo a passare l'immagine sul form non succede nulla, il simbolo del mouse resta quel cerchio sbarrato, come se non ci fosse nessun dragdrop.
Può essere che uso la versione Express? Ma con VS2005 che framework posso usare? Al max metterò il 2008, ho una copia di VS2008 Professional Beta 2 presa a una conferenza |
![]() |
![]() |
![]() |
#9 | |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Del FW 3.0 francamente non so quasi nulla, dato che sono passato direttamente da VS2003 a 2008 ( FW 3.5 ). Io dalla Beta2 di VS2008 ne starei alla larga. Fossi in te starei su VS 2005 + FW 2.0. Se invece trovi qualcuno che ti "presta" un VS2008 Full, vai decisamente su quello, e puoi scegliere di creare applicazioni 2.0, 3.0, o 3.5. Il massimo è il FW 3.5 SP1, che non ho ancora provato... ![]() |
|
![]() |
![]() |
![]() |
#10 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Niente da fare, ho provato a scaricare il framework 2.0 e a installarlo ma mi dice subito che è già installato con il sistema operativo, non me lo fa neanche ripristinare... Boh, proverò a scaricare VB2008 Express.
|
![]() |
![]() |
![]() |
#11 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Funziona!!! Evvai!!! Grazie dell'aiuto. Non so quale fosse il problema, comunque ho disinstallato tutto e poi ho installato VB2008 Express con SP1 e adesso funziona!
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:26.