Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 107,708 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 1,100 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Drag & Drop

Examples how to use drag & drop: 1) textbox to label Change the textbox text to label text 2) textbox to picturebox Add the textbox text country name to flag of a picturebox (example generates 6 flags) 3) textbox to listbox Add the textbox text to listbox

Submitted By: m2s87
Actions:
Rating:
Views: 5,523

Language: VB.NET

Last Modified: January 21, 2007

Snippet


  1. '
  2.     'Written by Margus Martsepp aka m2s87
  3.     '
  4.     Dim WithEvents x1 As New TextBox
  5.     Dim WithEvents x2 As New Label
  6.     Dim WithEvents x3 As New PictureBox
  7.     Dim WithEvents x4 As New ListBox
  8.  
  9.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.         With x1 : .Parent = Me : .AllowDrop = True : .Top = 10 : .Visible = True : End With
  11.         With x2 : .Parent = Me : .AllowDrop = True : .Top = 35 : .Visible = True _
  12.                 : .BackColor = Color.WhiteSmoke : End With
  13.         With x3 : .Parent = Me : .AllowDrop = True : .Top = 8 : .Left = 110 _
  14.                 : .BorderStyle = BorderStyle.FixedSingle : .Visible = True : End With
  15.         With x4 : .Parent = Me : .AllowDrop = True : .Top = 60 : .Width = 210 : .Visible = True : End With
  16.         With Me : .Size = New Size(220, 200) : .Text = "Drag & Drop" : End With
  17.     End Sub
  18.     '
  19.     'The source
  20.     '
  21.     Private Sub alla(ByVal sender As Object, ByVal e As MouseEventArgs) Handles x1.MouseDown
  22.         x1.DoDragDrop(x1.Text, DragDropEffects.Move)
  23.     End Sub
  24.     '
  25.     'Label
  26.     '
  27.     Private Sub sisse1(ByVal sender As Object, ByVal e As DragEventArgs) Handles x2.DragEnter
  28.         If (e.Data.GetDataPresent(DataFormats.Text)) Then
  29.             e.Effect = DragDropEffects.Move
  30.         End If
  31.     End Sub
  32.  
  33.     Private Sub lahti1(ByVal sender As Object, ByVal e As DragEventArgs) Handles x2.DragDrop
  34.         x2.Text = e.Data.GetData(DataFormats.Text).ToString
  35.         x1.Text = ""
  36.     End Sub
  37.     '
  38.     'Picturebox
  39.     '
  40.     Private Sub sisse2(ByVal sender As Object, ByVal e As DragEventArgs) Handles x3.DragEnter
  41.         If (e.Data.GetDataPresent(DataFormats.Text)) Then
  42.             e.Effect = DragDropEffects.Move
  43.         End If
  44.     End Sub
  45.  
  46.     Private Sub lahti2(ByVal sender As Object, ByVal e As DragEventArgs) Handles x3.DragDrop
  47.  
  48.         Select Case e.Data.GetData(DataFormats.Text).ToString.ToUpper
  49.             Case "EESTI", "ESTONIAN"
  50.                 Dim v() As System.Drawing.Color = {Color.RoyalBlue, Color.Black, Color.WhiteSmoke}
  51.                 x3.Image = lipp(v, x3.Width, x3.Height)
  52.             Case "DEUTSCHLAND", "GERMANY"
  53.                 Dim v() As System.Drawing.Color = {Color.Black, Color.Red, Color.Yellow}
  54.                 x3.Image = lipp(v, x3.Width, x3.Height)
  55.             Case "LATVIJA", "LATVIA"
  56.                 Dim v() As System.Drawing.Color = {Color.DarkRed, Color.WhiteSmoke, Color.DarkRed}
  57.                 x3.Image = lipp(v, x3.Width, x3.Height)
  58.             Case "LIETUVA", "LITHUANIA"
  59.                 Dim v() As System.Drawing.Color = {Color.DarkKhaki, Color.DarkGreen, Color.DarkRed}
  60.                 x3.Image = lipp(v, x3.Width, x3.Height)
  61.             Case "NEDERLAND", "NETHERLANDS"
  62.                 Dim v() As System.Drawing.Color = {Color.DarkRed, Color.WhiteSmoke, Color.DarkBlue}
  63.                 x3.Image = lipp(v, x3.Width, x3.Height)
  64.             Case "РОССИЯ", "RUSSIA"
  65.                 Dim v() As System.Drawing.Color = {Color.White, Color.Blue, Color.Red}
  66.                 x3.Image = lipp(v, x3.Width, x3.Height)
  67.             Case Else : x3.Image = Nothing
  68.         End Select
  69.  
  70.         x1.Text = ""
  71.     End Sub
  72.     '
  73.     'Generates the picture
  74.     '
  75.     Function lipp(ByVal v() As System.Drawing.Color, _
  76.                   Optional ByVal x As Integer = 200, _
  77.                   Optional ByVal y As Integer = 100) As Bitmap
  78.         Dim flag As New Bitmap(x, y)
  79.         Dim z As Integer
  80.  
  81.         For y = 0 To flag.Height - 1
  82.             z = IIf(y < Int(flag.Height / 3), 0, IIf(Int(flag.Height / 3) * 2 > y, 1, 2))
  83.             For x = 0 To flag.Width - 1
  84.                 flag.SetPixel(x, y, v(z))
  85.             Next x
  86.         Next y
  87.  
  88.         Return flag
  89.     End Function
  90.     '
  91.     'Listbox
  92.     '
  93.     Private Sub sisse3(ByVal sender As Object, ByVal e As DragEventArgs) Handles x4.DragEnter
  94.         If (e.Data.GetDataPresent(DataFormats.Text)) Then
  95.             e.Effect = DragDropEffects.Move
  96.         End If
  97.     End Sub
  98.  
  99.     Private Sub lahti3(ByVal sender As Object, ByVal e As DragEventArgs) Handles x4.DragDrop
  100.         x4.Items.Add(e.Data.GetData(DataFormats.Text).ToString)
  101.         x1.Text = ""
  102.     End Sub

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month