I have a winforms application that uses UserControl. The task of user management is to collect the file that the user dropped on it from Windows Explorer, open the file, determine the type and process it accordingly.
This control worked in Visual Studio 2008 Pro. I upgraded to VS 2010 Pro and now it does not work. Is there a flag or property that has changed that I should be aware of?
I did a quick demo for testing. This demo works fine in 2008, but doesn't work at all in 2010.
Customization: create a new winform project. Add a custom control. Set the following code in the user control code section. (compile so that the user control appears in the toolbar). Add a control to the form. Run the program and drag ANY file from the windows into the form. If it works, the user control area should change colors.
public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); this.AllowDrop = true; this.DragDrop += new DragEventHandler(UserControl1_DragDrop); this.DragEnter += new DragEventHandler(UserControl1_DragEnter); this.DragLeave += new EventHandler(UserControl1_DragLeave); } void UserControl1_DragLeave(object sender, EventArgs e) { this.BackColor = Color.FromName("Control"); } void UserControl1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; this.BackColor = Color.Blue; } else { e.Effect = DragDropEffects.None; } } void UserControl1_DragDrop(object sender, DragEventArgs e) { this.BackColor = Color.Yellow; } }
I am open to any explanations or corrections that you guys can come up with!
UPDATE:
I tested using the comments listed below. STILL does not work. However, I noticed that it only fails in the development environment. When I go to the bin directory and run the program manually, it works fine. It just doesn't work when I'm in the development environment, which makes debugging difficult. Still looking for a big picture fix.
Jerry source share