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

| Author: | TX Text Control Support Department |
| Language: | C# .NET |
| Version: | 1.0 |
| Released: | August 08, 2007 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control .NET with Visual Studio 2005 |
| Download code: | tx_drag_images.zip |
TX Text Control implements drag and drop events that can be used to handle almost all commonly used drag and drop approaches, such as opening files when the user drops a file from the File Explorer into TX Text Control.
This basic example illustrates how images can be dropped into TX Text Control, using these events. The images can be dropped into TX Text Control from the Windows File Explorer and will be inserted at the current mouse position.
First, the DragEnter event is used to check whether there are files to be dropped into TX Text Control.
private void textControl1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true) e.Effect = DragDropEffects.All; }
In the DragDrop event, the file names of the files that can be dropped are collected in a string array that is used in a loop to open all images, using the ImageCollection.Add method of TX Text Control. The coordinates that are passed to the event are used to position the image in the document.
private void textControl1_DragDrop(object sender, DragEventArgs e) { try { string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string fileName in fileNames) { TXTextControl.Image dropImage = new TXTextControl.Image(); dropImage.FileName = fileName; textControl1.Images.Add(dropImage, new Point((e.X * dpi) _ + textControl1.ScrollLocation.X - (this.Left * dpi), _ (e.Y * dpi) + textControl1.ScrollLocation.Y - (this.Top * dpi)), _ TXTextControl.ImageInsertionMode.DisplaceText); } } catch (Exception exc) { throw exc; } }
To use the downloadable version of this sample you need TX Text Control .NET 13.0 trial version or better.