I have a winforms app that uses a UserControl. The user control's job is to collect a file that the user drops on it from Windows Explorer, Open the file, determine the type and handle it accordingly.
This control worked PERFECTLY under Visual Studio 2008 Pro. I upgraded to VS 2010 Pro, and now, it doesn't work. Is there a flag or a property that has changed that I should be aware of??
I made a quick demo to test. This demo works perfectly under 2008, but doesn't work at all under 2010.
The setup: Create a new winform project. Add a user control. Set the following code in the user control's code section. (compile to get the user control to appear in the toolbox) Add the user control to the form. Run the program, and drag ANY file from windows onto 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'm open to any explanation or fix that you guys may think up!
UPDATE:
I tested using the comments listed below. STILL doesn't work. However, I have noted that it only fails while in the development environment. When I go to the bin directory and launch the program manually, it works fine. It just doesn't work when I am in the development environment, which makes debugging a bit difficult. Still looking for the big-picture fix.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…