vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Mails senden, abrufen und decodieren - ganz easy ;-)  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Re: drag&drop endstation? 
Autor: Maywood
Datum: 14.12.05 16:56

Hier ein kmpl. Beispiel:
 
Option Explicit On 
Option Strict On
 
Public Class Form1
    Inherits System.Windows.Forms.Form
 
#Region " Vom Windows Form Designer generierter Code "
 
#End Region
 
    Private source As PictureBox = Nothing
 
    Private Sub PictureBox_DragOver(ByVal sender As System.Object, ByVal e As _
      System.Windows.Forms.DragEventArgs)
        e.Effect = DragDropEffects.Move
    End Sub
 
    Private Sub PictureBox_DragEnter(ByVal sender As System.Object, ByVal e As _
      System.Windows.Forms.DragEventArgs)
        Dim pb As PictureBox = CType(sender, PictureBox)
        Application.DoEvents()
        Dim gr As Graphics = pb.CreateGraphics
        Dim x As Integer = 10, y As Integer = 10
        gr.DrawRectangle(New Pen(Color.White, 1), New Rectangle(0, 0, pb.Width _
          - 1, pb.Height - 1))
        gr.DrawString("Hierher verschieben..", Me.Font, Brushes.Red, x, y)
    End Sub
 
    Private Sub PictureBox_DragLeave(ByVal sender As System.Object, ByVal e As _
      EventArgs)
        Dim pb As PictureBox = CType(sender, PictureBox)
        pb.Refresh()
        Application.DoEvents()
    End Sub
 
    Private Sub PictureBox_DragDrop(ByVal sender As System.Object, ByVal e As _
      System.Windows.Forms.DragEventArgs)
        Try
            Dim pb As PictureBox = CType(sender, PictureBox)
            Dim newimg As Image = CType(e.Data.GetData(GetType(Bitmap)), Bitmap)
            source.Image = pb.Image
            pb.Image = newimg
            pb.Size = newimg.Size
            Application.DoEvents()
 
            Dim gr As Graphics = pb.CreateGraphics
            Dim x As Integer = 0, y As Integer = 0
            gr.DrawString("Wurde verschoben..", Me.Font, Brushes.White, x, y)
            Application.DoEvents()
            Threading.Thread.Sleep(1000)
            pb.Refresh()
            Application.DoEvents()
 
        Catch ex As Exception
            Debug.WriteLine(ex.ToString)
        End Try
    End Sub
 
    Private Sub PictureBox_MouseMove(ByVal sender As System.Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs)
        If e.Button = MouseButtons.Right Then
            Dim pb As PictureBox = CType(sender, PictureBox)
            Me.source = pb
            pb.DoDragDrop(pb.Image, DragDropEffects.Move)
        End If
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
      System.EventArgs) Handles MyBase.Load
        Dim pb As PictureBox = Nothing
        Dim img As Image = Nothing
        Dim fileName As String = Nothing
        Dim x As Integer = 0, y As Integer = 10
 
        For a As Integer = 0 To 3
            fileName = IO.Path.Combine(Application.StartupPath, (a + _
              1).ToString + ".bmp")
            pb = New PictureBox
            pb.AllowDrop = True
            img = New Bitmap(Image.FromFile(fileName), 200, 200)
            pb.Image = img
            pb.Size = img.Size
            pb.Location = New Point(x, y)
            x += pb.Size.Width
            Me.SetHandler(pb)
            Me.Controls.Add(pb)
        Next
        Me.Width = x + 20
    End Sub
 
    Private Sub SetHandler(ByVal pb As PictureBox)
        AddHandler pb.MouseMove, AddressOf PictureBox_MouseMove
        AddHandler pb.DragDrop, AddressOf PictureBox_DragDrop
        AddHandler pb.DragEnter, AddressOf PictureBox_DragEnter
        AddHandler pb.DragOver, AddressOf PictureBox_DragOver
        AddHandler pb.DragLeave, AddressOf PictureBox_DragLeave
    End Sub
 
End Class
Hatte gerade etwas Langeweile

(Du benötigst hierfür 4 Bilder (jeweils 0, 1, 2, 3.bmp) im Ausführungsordner und eine Form)
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
drag&drop endstation?890tekla13.12.05 20:07
Re: drag&drop endstation?629Maywood14.12.05 16:56
dankeschön502tekla15.12.05 02:08
Re: dankeschön500Maywood15.12.05 13:05

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel