Hi Tim,
I assume that the ActiveX Html Editor control you refer to is the HTML
Editor ActiveX control described in the following link:
http://nbit.net.au/vpages.aspx?ID=HTML Editor OCX
I performed a test on this HTML Editor ActiveX control in my WinForm
application and did reproduce the problem. Even if I set the KeyPreview
property of the form to true, the KeyDown event of the form doesn't get
fired when I press any key while the HTML Editor ActiveX control gets
focused.
I performed a test on Microsoft Web Browser ActiveX control and confirmed
that this problem doesn't exist on the Microsoft Web Browser ActiveX
control. So it seems that the problem doesn't exist on all unmanaged
control used in .NET programs.
When we add the HTML Editor ActiveX control into the Toolbox and drag it
onto a WinForm, VS IDE creates a wrapper class for this unmanaged control,
named AxrmpHTML.AxHTMLed. This class has exposed an event called
PreviewKeyDown. In fact, when we press any key when the HTML Editor ActiveX
control is focused, this PreviewKeyDown event is fired.
So a workaround of this problem is to set the KeyPreview property of the
form to true and handle the PreviewKeyDown event of the HTML Editor ActiveX
control. In this event handler, call the form's OnKeyDown method to get the
form's KeyDown event fired.
The following is a sample to do this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.KeyPreview = true;
this.KeyDown += new KeyEventHandler(Form1_KeyDown);
this.axHTMLed1.PreviewKeyDown += new
PreviewKeyDownEventHandler(axHTMLed1_PreviewKeyDown);
}
void axHTMLed1_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{
this.OnKeyDown(new KeyEventArgs(e.KeyCode));
}
void Form1_KeyDown(object sender, KeyEventArgs e)
{
Console.WriteLine("Form keydown:" + e.KeyCode.ToString());
}
}
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.