c# - Remove icon automatically by dropped file on RichTextBox -
i set true
allowdrop
implemented dragover
, dragdrop
events richtextbox. on dragdrop
event load dropped text files' contents on rtb add icon of file in rtb i'd remove it:
edit: here's 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 file\"{0}\" error: {1}", filename, ex.message); messagebox.show(errmsg, "reading file error", messageboxbuttons.ok, messageboxicon.error); return; } } msg_textbox.text = buffer.tostring(); }
somewhere have set msg_textbox.enableautodragdrop = true
, either in designer window or code. need set false. still need set allowdrop = true
.
when set true, winforms richtextbox
provides standard behaviors drag-and-drop events, custom handlers added. if don't want standard behavior, have roll own handlers. (the standard behavior dropped text file ole embedding. if double click on icon, notepad launches.)
Comments
Post a Comment