I set to true
the AllowDrop
implemented the DragOver
and DragDrop
events RichTextBox. On DragDrop
event I load the dropped text files' contents on the RTB but it does add the icon of the file in RTB I'd to remove it:
Edit: Here's my code:
void msg_setup_dragDrop()
{
msg_textBox.AllowDrop = true;
msg_textBox.EnableAutoDragDrop = true; msg_textBox.DragEnter += new DragEventHandler(msg_DragEnter); msg_textBox.DragDrop += new DragEventHandler(msg_DragDrop); }
void msg_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
}
void msg_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
StringBuilder buffer = new StringBuilder();
foreach (string filename in files)
{
try
{
string text = File.ReadAllText(filename);
buffer.Append(text);
}
catch (Exception ex)
{
string errMsg = string.Format("cannot read the file\"{0}\" error: {1}", filename, ex.Message);
MessageBox.Show(errMsg, "Reading file error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
msg_textBox.Text = buffer.ToString();
}
Aucun commentaire:
Enregistrer un commentaire