C# .NET 2 WinForms.
I need to open ComboBox dropdown list if user presses F12
I tried the code below (F4 opens dropdown list by default) but got compile
error
Property or indexer 'System.Windows.Forms.KeyEventArgs.KeyCode' cannot be
assigned to -- it is read only
How to fix ?
Andrus.
class MyComboBox : ComboBox {
protected override void OnKeyDown(KeyEventArgs e) {
if (e.KeyCode == Keys.F12)
e.KeyCode = Keys.F4;
base.OnKeyDown(e);
}
Try:
protected override void OnKeyDown(KeyEventArgs e) {
KeyEventArgs k = null;
if (e.KeyCode == Keys.F12)
k = new KeyEventArgs(Keys.F4);
else
k = new KeyEventArgs(e.KeyCode);
base.OnKeyDown(k);
}
> C# .NET 2 WinForms.
>
[quoted text clipped - 17 lines]
> base.OnKeyDown(e);
> }
christery@gmail.com - 03 Feb 2008 19:40 GMT
> Try:
>
[quoted text clipped - 31 lines]
>
> - Visa citerad text -
A Little devil is playing in my head, could I use that system wide?
installing a service/program that took every 10´th char and subst that
with X...
My friend is going to borneo for a vacation... this would be a great
treat (not for him maybe?) to bless his computer with this feature
when he returns...
I did something like this in DOS 20 years ago but that was to
intercept ctrl-c,dont think hooking interrupt 14 (or whatewer it was)
is applyable nowdays...
Will google for a solution, but if u have one it would be nice....
hope he doesnt look in this group...
//CY
Andrus - 03 Feb 2008 22:58 GMT
> Try:
> protected override void OnKeyDown(KeyEventArgs e) {
[quoted text clipped - 5 lines]
> base.OnKeyDown(k);
> }
I tried but dropdown menu is not opened when I press F12.
Andrus.
Simon Duvall - 04 Feb 2008 04:13 GMT
You're right! I apologize...
Ok this works. You need a custom combobox control.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
class Class1 : ComboBox
{
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.F12)
SendKeys.Send("{F4}");
base.OnKeyDown(e);
}
}
}
~simon
>> Try:
>> protected override void OnKeyDown(KeyEventArgs e) {
[quoted text clipped - 9 lines]
>
> Andrus.
Marc Gravell - 04 Feb 2008 08:12 GMT
As an alternative strategy to SendKeys etc (following just using an
event-handler):
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F12)
{
// suppress downstream handling
e.Handled = true;
// toggle drop
comboBox1.DroppedDown = !comboBox1.DroppedDown;
}
}