One of my friend asked me if there is a way that could prevent Images being pasted in the RichTextBox control, so I did a little code that allows RichTextBox control not to include Images.
The solution to this problem is very simple just override the OnKeyDown event and check if the clipboard contains data of Bitmap Type.
public class RichTextBoxWithoutImage:RichTextBox
{
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
/*check for Ctrl+V*/
if (e.Control && e.KeyCode == Keys.V)
{
IDataObject obj = Clipboard.GetDataObject();
if (obj.GetDataPresent(typeof(Bitmap)))
{
e.Handled = true;
}
}
}
}
Advertisement



Useful stuff brilliantly written. Thanx , it save my time.