Drag and Drop Files into the Current Input Position
While reviewing pre-sales support cases, I stumbled upon this interesting code snippet one of our sales engineers sent to a client to mimic a drag and drop feature of MS Word. In MS Word, you can drag and drop a file into an existing position in a document instead of replacing the current content with the new document. In TX Text Control, this can be done in a very easy way using the DragDrop event of TextControl: private void textControl1_DragDrop(object sender, DragEventArgs e) { Point…

While reviewing pre-sales support cases, I stumbled upon this interesting code snippet one of our sales engineers sent to a client to mimic a drag and drop feature of MS Word.
In MS Word, you can drag and drop a file into an existing position in a document instead of replacing the current content with the new document.
In TX Text Control, this can be done in a very easy way using the DragDrop event of TextControl:
private void textControl1_DragDrop(object sender, DragEventArgs e)
{
Point posCursor = textControl1.PointToClient(new Point(e.X, e.Y));
TXTextControl.TextChar txChar =
textControl1.TextChars.GetItem(posCursor, true);
textControl1.Selection.Start = txChar.Number;
textControl1.Selection.Load(fileDragDrop.FileName,
fileDragDrop.StreamType);
}
The TextChars.GetItem method returns the nearest input position of a given location. The location is returned from the event directly. All we need to do is to set the input position to the new calculated input position in order to load the document using the Selection object.

This code snippet is based on the shipped sample Howto: Drag and Drop Files and uses the same FileDragDropHandler.
Related Posts
Windows FormsGetting StartedTutorial
Windows Forms Tutorial: Create Your First Windows Forms C# Application
This tutorial shows how to create your first Windows Forms application with C# using TX Text Control .NET for Windows Forms in Visual Studio 2022.
How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#
Mail merge is the process of merging data, such as Json or IEnumerable objects, into a template document, such as a DOC or DOCX file. This tutorial is a walkthrough of the steps necessary to…
Creating an Angular Document Editor Application with a Node.js WebSocket Server
This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.
Adding SVG Watermarks to Documents
This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.
Using MailMerge in ASP.NET Core 6 Web Applications
This article shows how to use the TX Text Control ASP.NET MailMerge class to merge templates with JSON data within a .NET 6 application in Visual Studio 2022.