Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleDisplay a small drag icon with text in it
Keywordsdrag and drop, icon, text icon
CategoriesControls
 
Draw the text into a PictureBox. For icons, the picture should be 32 by 32 pixels.

Start the drag in a control's MouseDown event handler. Copy the picture into an ImageList control. Then use the ImageList control's ListImages collection's ExtractIcon method to get an icon. Set the control's DragIcon property to the icon and call the Drag method to start the drag.

 
' Set this control's DragIcon property.
Private Sub Label1_MouseDown(Index As Integer, Button As _
    Integer, Shift As Integer, X As Single, Y As Single)
Dim txt As String

    ' Write the text into the PictureBox.
    Picture1.Font.Name = Label1(Index).Font.Name
    Picture1.Font.Size = Label1(Index).Font.Size
    Picture1.Font.Bold = Label1(Index).Font.Bold
    Picture1.Line (0, 0)-(Picture1.ScaleWidth, _
        Picture1.ScaleHeight), Picture1.BackColor, BF

    txt = Label1(Index).Caption

    Picture1.CurrentX = (Picture1.ScaleWidth - _
        Picture1.TextWidth(txt)) / 2
    Picture1.CurrentY = (Picture1.ScaleHeight - _
        Picture1.TextHeight(txt)) / 2
    Picture1.Print Label1(Index).Caption
    Picture1.Picture = Picture1.Image

    ImageList1.ListImages.Clear
    ImageList1.ListImages.Add , , Picture1.Picture

    Label1(Index).DragIcon = _
        ImageList1.ListImages(1).ExtractIcon
    Label1(Index).Drag
End Sub
 
In the control's DragDrop event handler, handle the drop. This example switches the source and target Labels' Captions.
 
Private Sub Label1_DragDrop(Index As Integer, Source As _
    Control, X As Single, Y As Single)
Dim tmp As String

    If Not (TypeOf Source Is Label) Then Exit Sub

    tmp = Label1(Index).Caption
    Label1(Index).Caption = Source.Caption
    Source.Caption = tmp
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated