Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
|
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2008, 04:32 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default Drag From Word, Drop in TxtBox

Given a VB.NET 2005 and a textbox, txtSI.

I have set Allow Drop to True.

But when I highlight a set of characters in Word, and drag it over this box, nothing appears to happen.

What are the switches to switch and the settings to set to get a textbox to receive text through a drag and drop operation?
 
Old May 12th, 2008, 10:17 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

This works well:
Code:
    Private Sub txtSI_DragDrop(ByVal sender As Object, _
                               ByVal e As System.Windows.Forms.DragEventArgs _
                              ) Handles txtSI.DragDrop
        If (e.Data.GetDataPresent(DataFormats.Text)) Then _
            txtSI.Text = e.Data.GetData(DataFormats.Text).ToString()
    End Sub

    Private Sub txtSI_DragEnter(ByVal sender As Object, _
                                ByVal e As System.Windows.Forms.DragEventArgs _
                               ) Handles txtSI.DragEnter
         If (e.Data.GetDataPresent(DataFormats.Text)) Then
             e.Effect = DragDropEffects.Copy
    End Sub
Apparently during a drag operation, tere can be a variety of formats all available at the same time. This is why you cna drag from word (formatted text) into an email message that is plain text type. When Word/excel/Internet Explorer/whatever) is used as a source for a drag/drop operation, a rendering as text is created (if possible), one as RichText Format (if possible), and so on. So if gragging a section of a picture from Paint, no Text format would be present.

So the dragenter event can look to see if data of a particular format is present, and modify the cursor in accordance with whether you plan to be able to handle the format(s) that are present.

Accordingly, the dragDrop can make choices as to whether one of the formats present will be handled, as well as which will be used if there are more than one that can be handled.

So for instance (again, in Word), if you are dropping from a source that incluedes Text and File, Word can decide whether to insert the text, a link to the file, or the contents of the file. (I haven't tried this, so I don't know which would be the case.)

In the same way you can program your own applications to hendle that which you want it to handle. (You can create your own format identifiers, and write the code to process that datatype. So if you create a complex object called clsPhotoShoot, you could create a data type identifier -- a string -- to indicate that this type of object is being dragged, and you could look for that identifier where the dropping is taking place, and write a case to handle it. I saw a scheduling program for a Dr.’s office that allowed dragging a client’s appointments around on a calendar. That's just one example.)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Drag From Word, Drop in TextBox BrianWren Visual Basic 2005 Basics 0 May 9th, 2008 04:34 PM
Copy txtBox content to Word zjankov Access VBA 0 August 20th, 2007 07:04 AM
drag and drop image from listview to Word jacklin General .NET 0 August 14th, 2006 01:12 AM
Drag/Drop bmains Javascript 1 September 22nd, 2004 07:29 PM
Drag and drop image to word[:p] hary General .NET 0 July 24th, 2004 04:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.