Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Open ComBobox dropdown list when F12 pressed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrus - 03 Feb 2008 10:51 GMT
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);
}
Simon Duvall - 03 Feb 2008 15:52 GMT
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;
           }
       }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.