RichTextBox and Paste

  • Thread starter Daniel Bello Urizarri
  • Start date
D

Daniel Bello Urizarri

How can i prevent images for been pasted on a richtextbox? As i have seen,
all methods involving Paste and CanPaste operations are not virtual, so I
can not override its behavior.

I also want to prevent that users paste anithing but plain text.. Don't want
text with format, urls, diferent fonts. So i would like to filter what can
be pasted on the control..

Is there any way? Or I must override WndProc and work like if I was working
on win32.

Help!
 
P

Philip J. Fry

if(Clipboard.GetDataObject().GetDataPresent
(DataFormats.Text) == true)
{
.... paste
}

Phil
 
D

Daniel Bello Urizarri

Thanks Phil, but your answer is not exactly what Im Asking.. Take a look at
this code (the one im using now):

private void rtb_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
if (( e.KeyCode == Keys.V && e.Control ) ||
( e.KeyCode == Keys.Insert && e.Shift ))
{
IDataObject dobj = Clipboard.GetDataObject ();
if ( dobj != null )
{
string data = dobj.GetData ( typeof ( string )) as string ;
if ( data != null )
rtb.Paste ( DataFormats.GetFormat ( DataFormats.Text));
}
e.Handled = true;
}
}

It will work fine on Windows where the paste operations is done by pressing
Ctrl+V or Shift+Insert. But ¿If i have a system with a different key
combination or some other sort of input method...

I would like to know if there is any way to be notifyed when a "Paste"
operation is about to happen, so I can do my work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top