473,387 Members | 1,456 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,387 software developers and data experts.

KeyPress Question

meh
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}
Nov 16 '05 #1
7 8070
meh wrote:
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}


Isn't the following what you're after?

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}
Nov 16 '05 #2
Hi meh,

If you read carefully in MSDN there is written

MSDN:
"The KeyPress event is not raised by noncharacter keys; however, the
noncharacter keys do raise the KeyDown and KeyUp events."

Delete and Insert keys are non-character keys.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no*************@cox.net> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}

Nov 16 '05 #3
meh
Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Hi meh,

If you read carefully in MSDN there is written

MSDN:
"The KeyPress event is not raised by noncharacter keys; however, the
noncharacter keys do raise the KeyDown and KeyUp events."

Delete and Insert keys are non-character keys.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no*************@cox.net> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}


Nov 16 '05 #4
In this case it works with me.
If the problem is that you don't see a message box that says the Ctrl is
pressed that is because the Control is a modifier. Change the followng lines
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
to

if (e.Control)
{
MessageBox.Show("Pressed " + e.Modifiers);
}

and you'll see the message

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no*************@cox.net> wrote in message
news:uL*************@tk2msftngp13.phx.gbl... Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Hi meh,

If you read carefully in MSDN there is written

MSDN:
"The KeyPress event is not raised by noncharacter keys; however, the
noncharacter keys do raise the KeyDown and KeyUp events."

Delete and Insert keys are non-character keys.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no*************@cox.net> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key??? Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}



Nov 16 '05 #5
meh
The Control key works but
I cant get it to trap the Insert key...

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
{
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In this case it works with me.
If the problem is that you don't see a message box that says the Ctrl is
pressed that is because the Control is a modifier. Change the followng
lines
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}


to

if (e.Control)
{
MessageBox.Show("Pressed " + e.Modifiers);
}

and you'll see the message

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no*************@cox.net> wrote in message
news:uL*************@tk2msftngp13.phx.gbl...
Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
> Hi meh,
>
> If you read carefully in MSDN there is written
>
> MSDN:
> "The KeyPress event is not raised by noncharacter keys; however, the
> noncharacter keys do raise the KeyDown and KeyUp events."
>
> Delete and Insert keys are non-character keys.
> --
> HTH
> Stoitcho Goutsev (100) [C# MVP]
>
>
> "meh" <no*************@cox.net> wrote in message
> news:eg**************@TK2MSFTNGP10.phx.gbl...
>> This should wotk I think but its not trapping the Insert or Delete key??? >> Do I not have this written correctly?
>>
>>
>> if (e.KeyCode == Keys.Insert)
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> if (e.Control)
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> }
>> else if (e.Shift)
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> }
>> else
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> }
>>
>> }
>>
>>
>
>



Nov 16 '05 #6
> The Control key works but
I cant get it to trap the Insert key...

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
}

What do you mean?
In the code you posted if you don't trap the insert key you won't see the
message for the Control modifier.

How come it works?
When I test your code I got the message for both Insert and Ctrl. make sure
you trap KeyDown not KeyPress event. Then make sure that the treeview has
the focus. In order to focus the treeview you have to have nodes inserted.
--

Stoitcho Goutsev (100) [C# MVP]
"meh" <no*************@cox.net> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In this case it works with me.
If the problem is that you don't see a message box that says the Ctrl is
pressed that is because the Control is a modifier. Change the followng
lines
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}


to

if (e.Control)
{
MessageBox.Show("Pressed " + e.Modifiers);
}

and you'll see the message

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no*************@cox.net> wrote in message
news:uL*************@tk2msftngp13.phx.gbl...
Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
> Hi meh,
>
> If you read carefully in MSDN there is written
>
> MSDN:
> "The KeyPress event is not raised by noncharacter keys; however, the
> noncharacter keys do raise the KeyDown and KeyUp events."
>
> Delete and Insert keys are non-character keys.
> --
> HTH
> Stoitcho Goutsev (100) [C# MVP]
>
>
> "meh" <no*************@cox.net> wrote in message
> news:eg**************@TK2MSFTNGP10.phx.gbl...
>> This should wotk I think but its not trapping the Insert or Delete

key???
>> Do I not have this written correctly?
>>
>>
>> if (e.KeyCode == Keys.Insert)
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> if (e.Control)
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> }
>> else if (e.Shift)
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> }
>> else
>> {
>> MessageBox.Show("Pressed " + e.KeyCode);
>> }
>>
>> }
>>
>>
>
>



Nov 16 '05 #7
meh
As a follow up....5 hours later.....the reason the Insert and Delete key
were not being trapping was because I had a context menu assigned to the
treeview???

Go figure......

meh
"meh" <no*************@cox.net> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show("Pressed " + e.KeyCode);
}

}

Nov 16 '05 #8

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

Similar topics

1
by: dave | last post by:
I've designed a nice little App that works something like a spreadsheet using the MSHFlexgrid control. Many users are inclined to press the tab key, expecting the program to respond like excel...
4
by: phil_gg04 | last post by:
Dear Javascript Experts, I'm currently implementing Anyterm, a terminal emulator on a web page. It consists of an Apache module, some XmlHTTP and a bit of Javascript. The idea is to give you...
1
by: Darren Coleman | last post by:
I need help with 2 keyboard/input questions 1. How do i caputre all keypress events for my application/form? 2. How do I determine which keyboard sent the keypress? What i'm doing is using a...
3
by: Terry Olsen | last post by:
Is there anyway to cause a KeyPress event in a datagrid cell? The only way I get a keypress event is if none of the cells are selected. I was hoping to have the program respond to a certain...
3
by: Just Me | last post by:
I noticed that I don't get KeyDown nor KetPress events if NumLock is not on. I can probably find a workaround but it would be nice to know what the rules are. Can anyone tell me when KeyPress...
3
by: Nikolay Evseev | last post by:
Hi, I am trying to trace down the Enter key in my Form.KeyPress event handler. The KeyPreview property is set to false, so I'd assume that all key presses should go through my form's KeyPress...
2
by: Bob | last post by:
In that event, how can you find out if the keypress event was in a certain column? Say you have datagridview1, columnname1, columnName2 You want to do something only with the keypress event of...
5
by: Henry Jones | last post by:
I am new to C# and wanted to capture the KeyPress for a textbox. I created some code as follows: private void textBox3_KeyPress(object sender, System.EventArgs e) { this.textBox2.Text =...
4
by: Jeff | last post by:
....still new at this. ...hopefully a simple question Is there some practical way of altering the function of a keypress in Visual Web.net 2005 using VB without causing a postback on each...
2
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.