private void TextBox_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length == 1 && Path.GetExtension(files[0]) == ".txt") { string contents = File.ReadAllText(files[0]); myTextBox.Text = contents; } } }
private void ListBox_DragOver(object sender, DragEventArgs e) { if (e.KeyStates == DragDropKeyStates.ControlKey) { e.Effects = DragDropEffects.Copy; } else if (e.KeyStates == DragDropKeyStates.ShiftKey) { e.Effects = DragDropEffects.Move; } else if (e.KeyStates == DragDropKeyStates.None) { e.Effects = DragDropEffects.Move; } }Package library: PresentationCore.dll