| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic |
| Version: | 1.1 |
| Released: | October 02, 2002 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control ActiveX with Visual Basic |
| Download code: | drag_drop_images.zip |
This week we are going to show you how to make the most of the drag&drop functionality of TX Text Control.
To start off, have a look at the Visual Basic samples that are shipped with TX Text Control.
Here you should find a little sample application called "DragDrop". This sample shows how to use the new drag&drop functionality to move selected text into a TX Text Control.
This weeks' Top TX Tip shows how to use this feature to place an image with the mouse into a TX Text Control. Here is the Visual Basic code:
Private Sub TXTextControl1_DragDrop(Source As Control, X As Single, Y As Single) HorizontalScroll = TXTextControl1.ScrollPosX X = (X + HorizontalScroll) VerticalScroll = TXTextControl1.ScrollPosY Y = (Y + VerticalScroll) TXTextControl1.ObjectInsertFixed 0, "Image.bmp", X, Y, 100, 100, 0, 1, 3, 2, 0, 0, 0, 0 End Sub
First of all, you need a PictureBox that contains the same image, which will be inserted by the ObjectInsertFixed method. The DragMode of the PictureBox needs to be set to Automatic, so that it can be dragged.
The DragDrop event returns the current coordinates in twentieths of a point. These X and Y values need to added up with the current scroll position of the TX Text Control. To get these values we use the ScollPosX and ScrollPosY properties of the TX Text Control, which specify the position of the scroll bars in TWIPs*. The new values will be used as the PosX and PosY parameters of the ObjectInsertFixed method.
After this the picture will be inserted exactly at the position where image is dropped.
* Just in case you were wondering, a TWIP is a unit of measurement that is equal to 1/20 of a point, or 1/1440 of an inch. There are 567 TWIPs in a centimeter.