Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:05:23+00:00 2026-05-21T09:05:23+00:00

I’m using a HtmlEditor control inside a Windows Form. I got the control from

  • 0

I’m using a HtmlEditor control inside a Windows Form.

I got the control from this page:

http://windowsclient.net/articles/htmleditor.aspx

I want to extend the controls functionality by allowing the user to paste images from the clipboard. Right now you can paste plain and formatted text, but when trying to paste an image it does nothing.

Basically what I thought was to detect when the user presses Ctrl+V on the editor, check the clipboard for images and if there’s an image, insert it manually to the editor.

The problem with this approach is that I cannot get the OnKeyDown or OnKeyPress events of the form to be raised.

I have the KeyPreview property set to true on the form, but still the events aren’t raised.

I also tried to Subclass the form and the editor (as explained here) to intercept the WM_PASTE message, but it isn’t raised either.

Any ideas on how to achieve this?

Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:05:24+00:00Added an answer on May 21, 2026 at 9:05 am

    I spent all day on this problem and finally have a solution. Trying to listen for the WM_PASTE message doesn’t work because Ctrl-V is being PreProcessed by the underlying mshtml Control. You can listen for OnKeyDown/Up etc to catch a Ctrl-V but this won’t stop the underlying Control from proceeding with its default Paste behavior. My solution is to prevent the PreProcessing of the Ctrl-V message and then implementing my own Paste behavior. To stop the control from PreProcessing the CtrlV message I had to subclass my Control which is AxWebBrowser,

    public class DisabledPasteWebBrowser : AxWebBrowser
    {
        const int WM_KEYDOWN = 0x100;
        const int CTRL_WPARAM = 0x11;
        const int VKEY_WPARAM = 0x56;
    
        Message prevMsg;
        public override bool PreProcessMessage(ref Message msg)
        {
            if (prevMsg.Msg == WM_KEYDOWN && prevMsg.WParam == new IntPtr(CTRL_WPARAM) && msg.Msg == WM_KEYDOWN && msg.WParam == new IntPtr(VKEY_WPARAM))
            {
                // Do not let this Control process Ctrl-V, we'll do it manually.
                HtmlEditorControl parentControl = this.Parent as HtmlEditorControl;
                if (parentControl != null)
                {
                    parentControl.ExecuteCommandDocument("Paste");
                }
                return true;
            }
            prevMsg = msg;
            return base.PreProcessMessage(ref msg);
        }
    }
    

    Here is my custom method to handle Paste commands, yours might do something similar with the Image data from the Clipboard.

        internal void ExecuteCommandDocument(string command, bool prompt)
        {
            try
            {
                // ensure command is a valid command and then enabled for the selection
                if (document.queryCommandSupported(command))
                {
                    if (command == HTML_COMMAND_TEXT_PASTE && Clipboard.ContainsImage())
                    {
                        // Save image to user temp dir
                        String imagePath = Path.GetTempPath() + "\\" + Path.GetRandomFileName() + ".jpg";
                        Clipboard.GetImage().Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        // Insert image href in to html with temp path
                        Uri uri = null;
                        Uri.TryCreate(imagePath, UriKind.Absolute, out uri);
                        document.execCommand(HTML_COMMAND_INSERT_IMAGE, false, uri.ToString());
                        // Update pasted id
                        Guid elementId = Guid.NewGuid();
                        GetFirstControl().id = elementId.ToString();
                        // Fire event that image saved to any interested listeners who might want to save it elsewhere as well
                        if (OnImageInserted != null)
                        {
                            OnImageInserted(this, new ImageInsertEventArgs { HrefUrl = uri.ToString(), TempPath = imagePath, HtmlElementId = elementId.ToString() });
                        }
                    }
                    else
                    {
                        // execute the given command
                        document.execCommand(command, prompt, null);
                    }
                }
            }
            catch (Exception ex)
            {
                // Unknown error so inform user
                throw new HtmlEditorException("Unknown MSHTML Error.", command, ex);
            }
    
        }
    

    Hope someone finds this helpful and doesn’t waste a day on it like me today.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.