Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Drag and drop images into TX Text Control

This source code snippet requires TX Text Control ActiveX
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 Download [2.31 KB, 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:

  1. Private Sub TXTextControl1_DragDrop(Source As Control, X As Single, Y
  2. As Single)
  3. HorizontalScroll = TXTextControl1.ScrollPosX
  4. X = (X + HorizontalScroll)
  5. VerticalScroll = TXTextControl1.ScrollPosY
  6. Y = (Y + VerticalScroll)
  7. TXTextControl1.ObjectInsertFixed 0, "Image.bmp", X, Y, 100,
  8. 100, 0, 1, 3, 2, 0, 0, 0, 0
  9. 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.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place