473,378 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Arrow Keys neglected on User Control

/*
I have problems detecting the Arrow Keys on a User Control. A control
derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys
but does react on the combination <Altor <Ctrl+ Arrow Key. The code
below shows what I mean. How can I cure this? (excuse me for the line
breaks)
*/


//class KeyTest
class KeyTest:System.Windows.Forms.Control
{
//data member label
System.Windows.Forms.Label label=new System.Windows.Forms.Label();
//constructor
KeyTest()
{
Controls.Add(label);
KeyDown+=OnKeyDown;
Text="Arrow Keys are Special?";
label.Text="\nPress <1>...";
Dock=System.Windows.Forms.DockStyle.Fill;
label.Dock=System.Windows.Forms.DockStyle.Fill;
}
//OnKeyDown
void OnKeyDown(object a,System.Windows.Forms.KeyEventArgs b)
{
switch(b.KeyCode)
{
case System.Windows.Forms.Keys.D1:
label.Text+="\nYou pressed 1."+
"\n\nNow hold down <Altor <Ctrland press the Arrow Up Key...";
break;
case System.Windows.Forms.Keys.Up:
label.Text+="\nYou pressed the Arrow Up Key."+
"\n\nNow release <Altor <Ctrland press the Arrow Up Key
again..."+
"\n\nIt doesn't work!"+
"\nPress <Escor <Spaceto Quit";
break;
case System.Windows.Forms.Keys.Escape:
System.Windows.Forms.Application.Exit();
break;
case System.Windows.Forms.Keys.Space:
System.Windows.Forms.Application.Exit();
break;
}
}
//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Form form=new System.Windows.Forms.Form();
form.Controls.Add(new KeyTest());
System.Windows.Forms.Application.Run(form);
}
}

Oct 26 '06 #1
1 10106
override IsInputKey and do something like this:

protected override bool IsInputKey(System.Windows.Forms.Keys
keyData)
{
switch (keyData & Keys.KeyCode)
{
case Keys.Up:
return true;
case Keys.Down:
return true;
case Keys.Right:
return true;
case Keys.Left:
return true;
default:
return base.IsInputKey(keyData);
}

}

--

Regards, Peter

"Martijn Mulder" <i@mskrev i meddelandet
news:45***********************@news.wanadoo.nl...
/*
I have problems detecting the Arrow Keys on a User Control. A control
derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys
but does react on the combination <Altor <Ctrl+ Arrow Key. The code
below shows what I mean. How can I cure this? (excuse me for the line
breaks)
*/


//class KeyTest
class KeyTest:System.Windows.Forms.Control
{
//data member label
System.Windows.Forms.Label label=new System.Windows.Forms.Label();
//constructor
KeyTest()
{
Controls.Add(label);
KeyDown+=OnKeyDown;
Text="Arrow Keys are Special?";
label.Text="\nPress <1>...";
Dock=System.Windows.Forms.DockStyle.Fill;
label.Dock=System.Windows.Forms.DockStyle.Fill;
}
//OnKeyDown
void OnKeyDown(object a,System.Windows.Forms.KeyEventArgs b)
{
switch(b.KeyCode)
{
case System.Windows.Forms.Keys.D1:
label.Text+="\nYou pressed 1."+
"\n\nNow hold down <Altor <Ctrland press the Arrow Up Key...";
break;
case System.Windows.Forms.Keys.Up:
label.Text+="\nYou pressed the Arrow Up Key."+
"\n\nNow release <Altor <Ctrland press the Arrow Up Key
again..."+
"\n\nIt doesn't work!"+
"\nPress <Escor <Spaceto Quit";
break;
case System.Windows.Forms.Keys.Escape:
System.Windows.Forms.Application.Exit();
break;
case System.Windows.Forms.Keys.Space:
System.Windows.Forms.Application.Exit();
break;
}
}
//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Form form=new System.Windows.Forms.Form();
form.Controls.Add(new KeyTest());
System.Windows.Forms.Application.Run(form);
}
}

Oct 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Darren Oakey | last post by:
ok - the problem - I made a simple breakout game out of a form, just painting the background - and using keydown for left and right arrow keys to control the bat - worked fine. I then moved all...
7
by: Seash | last post by:
Hi friends , here is the sample code private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar == 13) //enter { txtbox2.Focus(); }
4
by: Neil Wallace | last post by:
Hi there, I have an application in which a grid of 100 or more buttons are put on a form in columns of 10. All the buttons are within a panel. They are added in runtime, and so they adopt a...
11
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
2
by: Vincent | last post by:
Hi, I have a user control that needs to trap the arrow keys to move items around internally. However, using the arrow keys will move the focus to another control on the form hosting the user...
0
by: Martijn Mulder | last post by:
/* I override IsInputKey() to direct the Arrow Keys (Cursor Keys) to my custom System.Windows.Forms.Control. But, holding down the Shift-Key prevents the Arrow Keys from coming through. How can...
4
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually,...
2
by: Charles Law | last post by:
I'll kick myself when you tell me, but ... I have a user control on a form, and I want the user control to see the arrow keys when I press them. If I press just about any other key the control's...
2
by: Artie | last post by:
Hi, I want to force the user to only use the drop down and calendar to select a date in the DatetimePicker control. I do NOT want them to select the control, then use the up and down arrow...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.