|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
KeyPreview/KeyDown not working with ActiveXhi,
i have an ActiveX Html Editor control developed X-Standard.com. i'm trying to program in keyboard shortcuts via the KeyDown event attached to the form that contains the editor control. KeyPreview is set to on, but the KeyDown event does not fire if the focus is inside the editor. is this to be expected for unmanaged controls? thanks in advance tim 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%20Editor%20OCX 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. hi Linda,
thanks for the follow up. unfortunately the ActiveX editor i'm using doesn't expose a PreviewKeyDown property, or any keyboard events, so it looks like i'm stuck! the editor you posted is developed by NBit, the one i'm using is from XStandard. thanks anyway, it's not a real show-stopper. tim Show quote "Linda Liu[MSFT]" <v-l***@online.microsoft.com> wrote in message news:0WtQ9o3GIHA.5176@TK2MSFTNGHUB02.phx.gbl... > 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%20Editor%20OCX > > 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. > Hi Tim,
Thank you for your prompt response! > unfortunately the ActiveX editor i'm using doesn't expose a PreviewKeyDown property, or any keyboard eventsI mean the PreviewKeyDown event, not property. In fact, the PreviewKeyDown event I mentioned is derived from the System.Windows.Forms.Control class, because the wrapper class generated for the unmanaged ActiveX control is derived from the System.Windows.Forms.AxHost class, which is in turn derived from the System.Windows.Forms.Control class. > the editor you posted is developed by NBit, the one i'm using is from Do you mean you're using XStandard Lite(Win/OS x)? XStandard. I have downloaded the XStandard Lite(Win/OS x) from the following link: http://xstandard.com/en/downloads/ and installed it on my machine. I add the XStandard ActiveX control into Toolbox and drag this ActiveX control from Toolbox onto a form. VS IDE generates a wrpper class named AxXStandard.AxXHTMLEditor derived from the AxHost class. Now the resulted control named axXHTMLEditor1 has a PreviewKeyDown event, which we could subscribe to get notified when any key is press while the ActiveX control gets focused. Hope this helps. If you have anything unclear, please feel free to let me know. Sincerely, Linda Liu Microsoft Online Community Support hi Linda.
i really appreciate you taking the time to check this out so thoroughly. i have found out that VS 2005+ does generate a PreviewKeyDown event for ActiveX controls. however, the app i was working on was targeting.Net 1.1 so i was using VS 2003, and this doesn't have such an event for ActiveX. fortunately i just found that my client base have .net 2 installed now so i can finally upgrade and use VS 2008 for all my apps :) thanks again, problem solved! tim Show quote "Linda Liu[MSFT]" <v-l***@online.microsoft.com> wrote in message news:8TPlCvGHIHA.540@TK2MSFTNGHUB02.phx.gbl... > Hi Tim, > > Thank you for your prompt response! > >> unfortunately the ActiveX editor i'm using doesn't expose a > PreviewKeyDown property, or any keyboard events > > I mean the PreviewKeyDown event, not property. > > In fact, the PreviewKeyDown event I mentioned is derived from the > System.Windows.Forms.Control class, because the wrapper class generated > for > the unmanaged ActiveX control is derived from the > System.Windows.Forms.AxHost class, which is in turn derived from the > System.Windows.Forms.Control class. > >> the editor you posted is developed by NBit, the one i'm using is from > XStandard. > > Do you mean you're using XStandard Lite(Win/OS x)? > > I have downloaded the XStandard Lite(Win/OS x) from the following link: > http://xstandard.com/en/downloads/ > and installed it on my machine. > > I add the XStandard ActiveX control into Toolbox and drag this ActiveX > control from Toolbox onto a form. VS IDE generates a wrpper class named > AxXStandard.AxXHTMLEditor derived from the AxHost class. > > Now the resulted control named axXHTMLEditor1 has a PreviewKeyDown event, > which we could subscribe to get notified when any key is press while the > ActiveX control gets focused. > > Hope this helps. > If you have anything unclear, please feel free to let me know. > > Sincerely, > Linda Liu > Microsoft Online Community Support > Hi Tim,
Thank you for your feeback! Sorry that I should have mentioned in my first reply that I was using VS 2005. I perform a test in VS.NET 2003 and do see that the wrapper class for the ActiveX control doesn't expose the PreviewKeyDown event or any other key down related events. It seems that VS 2005 makes a progress in this field : ) If you have any other questions in the future, please don't hesitate to contact us. It's always our pleasure to be of assistance! 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. |
|||||||||||||||||||||||