<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>JMSoftware &#187; Practical</title>
	<atom:link href="http://www.jmsoftware.co.uk/blog/tag/practical/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jmsoftware.co.uk</link>
	<description>Software Development</description>
	<lastBuildDate>Mon, 26 Sep 2011 13:38:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Dragging and dropping onto a RichTextBox</title>
		<link>http://www.jmsoftware.co.uk/blog/dragging-and-dropping-onto-a-richtextbox</link>
		<comments>http://www.jmsoftware.co.uk/blog/dragging-and-dropping-onto-a-richtextbox#comments</comments>
		<pubDate>Tue, 24 Jul 2007 12:38:36 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[drag_drop]]></category>
		<category><![CDATA[drop_operations]]></category>
		<category><![CDATA[filenames]]></category>
		<category><![CDATA[intellisense]]></category>
		<category><![CDATA[net_framework]]></category>
		<category><![CDATA[Practical]]></category>
		<category><![CDATA[RichTextBox]]></category>
		<category><![CDATA[richtextbox_control]]></category>

		<guid isPermaLink="false">http://www.jmsoftware.co.uk/blog/dragging-and-dropping-onto-a-richtextbox</guid>
		<description><![CDATA[One of many flaws with the RichTextBox control is its lack of support for drag/drop operations. Luckily it&#8217;s simple to add. In fact, it&#8217;s so simple you&#8217;ll wonder why they didn&#8217;t just support it out of the box. Let&#8217;s assume &#8230; <a href="http://www.jmsoftware.co.uk/blog/dragging-and-dropping-onto-a-richtextbox">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of many flaws with the RichTextBox control is its lack of support for drag/drop operations. Luckily it&#8217;s simple to add. In fact, it&#8217;s so simple you&#8217;ll wonder why they didn&#8217;t just support it out of the box.<span id="more-16"></span></p>
<p>Let&#8217;s assume that you&#8217;ve created a form and added a RichTextBox called richTextBox1. Rather then going to the properties window to add the events, you&#8217;ll need to do it yourself.</p>
<p>Add the following in the constructor of the form:</p>
<pre><code>richTextBox1.AllowDrop = true;
richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
richTextBox1.DragEnter += new DragEventHandler(richTextBox1_DragEnter);</code></pre>
<p>Type in the &#8220;+=&#8221; and press tab to automatically complete the line, then press tab again to create the function. Or just add the handler functions manually:</p>
<pre><code>public void richTextBox1_DragEnter(object sender, DragEventArgs e) {
	if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
		e.Effect = DragDropEffects.Copy;
	}
	else {
		e.Effect = DragDropEffects.None;
	}
}

public void richTextBox1_DragDrop(object sender, DragEventArgs e) {
	string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop);

	foreach (string filename in filenames) {
		// code to process a filename
	}
}</code></pre>
<p>You can also implement DragOver and DragLeave in the same way, although those are there to &#8220;support the .NET Framework infrastructure&#8221; and are &#8220;not intended to be used directly from your code&#8221;. Intellisense doesn&#8217;t even show those events, but you can type them in and compile without problems. Also note that DragLeave is an EventHandler rather then a DragEventHandler.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jmsoftware.co.uk/blog/dragging-and-dropping-onto-a-richtextbox/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

