<?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/"
	>

<channel>
	<title>dotnet thoughts &#187; Drag and Drop</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/drag-and-drop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Drag and Drop in Silverlight 3</title>
		<link>http://www.dotnetthoughts.net/2010/09/20/drag-and-drop-in-silverlight-3/</link>
		<comments>http://www.dotnetthoughts.net/2010/09/20/drag-and-drop-in-silverlight-3/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 18:46:57 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Drag and Drop]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1086</guid>
		<description><![CDATA[One of the forums I found a question like how can I implement drag and drop in Silverlight. Today I got a chance to explore Silverlight drag and drop. I haven’t checked whether SL4 supports Drag and Drop, here is &#8230; <a href="http://www.dotnetthoughts.net/2010/09/20/drag-and-drop-in-silverlight-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the forums I found a question like how can I implement drag and drop in Silverlight. Today I got a chance to explore Silverlight drag and drop. I haven’t checked whether SL4 supports Drag and Drop, here is a simple implementation, which allow user to move the controls in runtime. I am using a rectangle as the control to drag and I placed the rectangle in a canvas.</p>
<p>XAML Code</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Canvas x:Name=&quot;LayoutRoot&quot; Background=&quot;Gray&quot;&gt;
    &lt;Rectangle Height=&quot;20&quot; Width=&quot;40&quot; Fill=&quot;Blue&quot;
                MouseLeftButtonDown=&quot;Rectangle_MouseLeftButtonDown&quot;
                MouseLeftButtonUp=&quot;Rectangle_MouseLeftButtonUp&quot;
                MouseMove=&quot;Rectangle_MouseMove&quot; Canvas.Left=&quot;109&quot; Canvas.Top=&quot;88&quot;&gt;
    &lt;/Rectangle&gt;
&lt;/Canvas&gt;
</pre>
<p>And here is the C# Code.</p>
<pre class="brush: csharp; title: ; notranslate">
//To store the initial location of the control.
private Point _StartPoint = default(Point);
//To check whether user started dragging the control.
private bool _IsMouseCaptured = false;

private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    UIElement uiElement = sender as UIElement;
    //Reading the current position
    _StartPoint = e.GetPosition(uiElement);
    //Capturing the Mouse.
    this._IsMouseCaptured = uiElement.CaptureMouse();
}

private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    //Releasing the Mouse and setting the variable to false.
    UIElement uiElement = sender as UIElement;
    uiElement.ReleaseMouseCapture();
    this._IsMouseCaptured = false;
}

private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
    //If the Mouse captured, set the Left and Top values of the control
    if (this._IsMouseCaptured)
    {
        UIElement uiElement = sender as UIElement;
        Canvas.SetLeft(uiElement, (e.GetPosition(this).X - this._StartPoint.X));
        Canvas.SetTop(uiElement, (e.GetPosition(this).Y - this._StartPoint.Y));
    }
}
</pre>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/01/06/file-uploader-using-silverlight-and-wcf/" title="Permanent link to File Uploader using Silverlight and WCF">File Uploader using Silverlight and WCF</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/04/how-to-access-sharepoint-list-items-using-silverlight-object-model/" title="Permanent link to How to access SharePoint List Items using Silverlight Object Model">How to access SharePoint List Items using Silverlight Object Model</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/07/03/image-cropping-control-in-c-for-windows-forms/" title="Permanent link to Image cropping control in C# for Windows Forms">Image cropping control in C# for Windows Forms</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/17/developing-a-simple-rss-reader-in-c-net/" title="Permanent link to Developing a simple RSS Reader in C#.Net">Developing a simple RSS Reader in C#.Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/07/04/drag-and-drop-files-from-windows-to-your-application/" title="Permanent link to Drag and Drop files from Windows to your application">Drag and Drop files from Windows to your application</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/09/20/drag-and-drop-in-silverlight-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Drag and Drop files from Windows to your application</title>
		<link>http://www.dotnetthoughts.net/2009/07/04/drag-and-drop-files-from-windows-to-your-application/</link>
		<comments>http://www.dotnetthoughts.net/2009/07/04/drag-and-drop-files-from-windows-to-your-application/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 19:17:52 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[Drag and Drop]]></category>
		<category><![CDATA[Drag Drop]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=297</guid>
		<description><![CDATA[While working around an Script Editor application, I found that in almost all the editors we can drag and drop files from Windows.(Even MS Notepad supports it.) Then I searched for an implementation, but unfortunately I can&#8217;t find a perfect &#8230; <a href="http://www.dotnetthoughts.net/2009/07/04/drag-and-drop-files-from-windows-to-your-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While working around an Script Editor application, I found that in almost all the editors we can drag and drop files from Windows.(Even MS Notepad supports it.) Then I searched for an implementation, but unfortunately I can&#8217;t find a perfect one. Then I thought of implementing the same. I am not sure this one is a perfect implementation or not, but it works fine for me. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is the code. Seems like it is self explanatory</p>
<pre class="brush: vb; title: ; notranslate">
Imports System.IO
Public Class frmMain

    Private Sub txtEditor_MouseDown(ByVal sender As System.Object, _
                                    ByVal e As System.Windows.Forms.MouseEventArgs) _
                                    Handles txtEditor.MouseDown
        'Initiating the Drag and Drop
        txtEditor.DoDragDrop(&quot;&quot;, DragDropEffects.Copy)
    End Sub

    Private Sub txtEditor_DragEnter(ByVal sender As System.Object, _
                                    ByVal e As System.Windows.Forms.DragEventArgs) _
                                    Handles txtEditor.DragEnter
        'Ensures the dragging data is valid type.
        'Then only setting the drop effect.
        'Otherwise you will see no drop cursor, instead of Copy
        If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If

    End Sub

    Private Sub txtEditor_DragDrop(ByVal sender As System.Object, _
                                   ByVal e As System.Windows.Forms.DragEventArgs) _
                                   Handles txtEditor.DragDrop
        'Getting the filename.
        'The length of files array will be based on the number of files dragging.
        Dim files As String() = e.Data.GetData(DataFormats.FileDrop)
        'Checking the files(0) is Sql File.
        If Path.GetExtension(files(0)).Equals(&quot;.sql&quot;, _
                                              StringComparison.CurrentCultureIgnoreCase) Then
            'Reading it using Stream reader
            Me.Text = String.Format(&quot;Drag Drop demo - {0}&quot;, _
                                    Path.GetFileNameWithoutExtension(files(0)))
            Using sr As New StreamReader(files(0))
                Me.txtEditor.Text = sr.ReadToEnd
            End Using
        Else
            'Otherwise displaying message box
            MessageBox.Show(&quot;Only supports SQL files&quot;)
        End If
    End Sub
End Class
</pre>
<p>Here is the screen shot</p>
<div id="attachment_300" class="wp-caption alignnone" style="width: 413px"><a href="http://anuraj.files.wordpress.com/2009/07/screenshot.jpg"><img src="http://anuraj.files.wordpress.com/2009/07/screenshot.jpg" alt="Drag and Drop Demo - Screenshot" title="screenshot" width="403" height="284" class="size-full wp-image-300" /></a><p class="wp-caption-text">Drag and Drop Demo - Screenshot</p></div>
<p>If some one know a better implementation please let me know.</p>
<p>More details from MSDN :<a href="http://msdn.microsoft.com/en-us/library/aa984430%28VS.71%29.aspx" target="_blank">Performing Drag-and-Drop Operations in Windows Forms</a></p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2009/08/19/using-background-worker-in-c/" title="Permanent link to Using background worker in C#">Using background worker in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/" title="Permanent link to Application development using Gtk# in .Net">Application development using Gtk# in .Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/22/adding-and-reading-files-from-sql-server-2008-filestream/" title="Permanent link to Adding and Reading files from SQL Server 2008 Filestream">Adding and Reading files from SQL Server 2008 Filestream</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/10/07/how-to-store-and-retrieve-files-from-sql-server-database/" title="Permanent link to How to Store and Retrieve files from SQL Server Database">How to Store and Retrieve files from SQL Server Database</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/06/12/a-simple-splash-screen-in-c/" title="Permanent link to A Simple Splash screen in C#">A Simple Splash screen in C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/07/04/drag-and-drop-files-from-windows-to-your-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

