I am using a winform HTML Editor which uses AxSHDocVw.AxWebBrowser
.
User are copying and pasting text from other software into this control.
The problem is that, on paste Ctrl-V it add few font tags to preserve formatting.
I do not want to preserve formatting, it should paste clean text without formatting or at least should not add there FONT
tags.
What i think is to intercept Ctrl-V and before pasting cleanup clipboard text.
So, I tried to intercept WM_PASTE
message and replace clipboard content with fixed test (just to check) as below
class myWB : AxSHDocVw.AxWebBrowser
{
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x302) // Trap WM_PASTE:
{
Clipboard.Clear();
Clipboard.SetText("some text");
return;
}
base.WndProc(ref m);
}
}
But it was not working. I added following before IF block to see if it is receiving WM_PASTE
message.
Debug.WriteLine(m.Msg);
On run, i didn't see there 0x302 (770) in output window even after multiple Ctrl-V.
Is it not receiving that message?
Then what is the way to do it? How do i cleanup text before paste?
WM_PASTE is not a notification, it is a command. That you'd send to an EDIT control to have it paste the clipboard into the control.
Of course a web browser is not an edit box so doesn't do it the same way. You will need to intercept the IHtmlElement2.onpaste event instead.