473,324 Members | 2,400 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,324 software developers and data experts.

Cant Intercept DEL Key .. not recognized ...

Hi Folks,

Problem is, that on one of my controls the DEL key wont work in
textboxes. i have different controls of this kind in my app and this
is the only one the DEL Key wont do his job. BACKSPACE and rightclick
menu delete works either. seems the DEL Key fires no event ... i
insert following code in my project to check this. no mehthod call if
DEL key hit ... any solution or idea for this problem ?
cant say ... users on this tabcontrol you cant use DEL if it works in
all other parts :(

private void OnKeyDown(object sender,KeyEventArgs AArgs)

{

base.OnKeyDown(AArgs);

System.Windows.Forms.Keys LKey =
System.Windows.Forms.Keys.KeyCode &
AArgs.KeyCode;

switch (LKey)

{

case System.Windows.Forms.Keys.Delete :

MessageBox.Show("DEL Key!");

break;

}

}
Nov 15 '05 #1
9 4329
Well, First I would call base.OnKeyDown... after my code. Not that I
actually call it at all, it gets called anyway.

Second, using the bitmask is for extracting KeyValue to obtain the
KeyCode. You already have the KeyCode in AArgs.KeyCode so there is no
need to use the bitmask.

Third, the code is valid and a textbox does fire an event on the delete
key so somehow your code isn't tied to it.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
Dan,

Your code you posted should be intercepting the delete key.

One idea my be that the KeyUp event was added incorrectly. Make sure
the following line of code was added to you InitializeComponent()
method.

this.textBox1.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.OnKeyDow n);

If this doesn't help, if you could post or email me your source for
the form I would be willing to help figure out the problem.

Glen Jones MCSD
da****@oxigem.com (Dan K.) wrote in message news:<cf**************************@posting.google. com>...
Hi Folks,

Problem is, that on one of my controls the DEL key wont work in
textboxes. i have different controls of this kind in my app and this
is the only one the DEL Key wont do his job. BACKSPACE and rightclick
menu delete works either. seems the DEL Key fires no event ... i
insert following code in my project to check this. no mehthod call if
DEL key hit ... any solution or idea for this problem ?
cant say ... users on this tabcontrol you cant use DEL if it works in
all other parts :(

private void OnKeyDown(object sender,KeyEventArgs AArgs)

{

base.OnKeyDown(AArgs);

System.Windows.Forms.Keys LKey =
System.Windows.Forms.Keys.KeyCode &
AArgs.KeyCode;

switch (LKey)

{

case System.Windows.Forms.Keys.Delete :

MessageBox.Show("DEL Key!");

break;

}

}

Nov 15 '05 #3
sorry for the late answer ... was on holiday the last weeks :)

problem still active ...

at my view its not the implemententation of the of the keydown event
cause this implementation was only a test to check if DEL Key fires an
event.
the naturally DEL Function (delete content) dont do his job on this
control. the test should only show why.
but its still not clear for me. any further idea ?

glen can i still send you the source of this control to check ?
Nov 15 '05 #4
I may be out of topic. I do not have the history of this message. However,
If you are playing with a form, what about this:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData==Keys.Delete)
{
MessageBox.Show("Delete pressed!");
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}

José
"Dan K." <da****@oxigem.com> wrote in message
news:cf**************************@posting.google.c om...
sorry for the late answer ... was on holiday the last weeks :)

problem still active ...

at my view its not the implemententation of the of the keydown event
cause this implementation was only a test to check if DEL Key fires an
event.
the naturally DEL Function (delete content) dont do his job on this
control. the test should only show why.
but its still not clear for me. any further idea ?

glen can i still send you the source of this control to check ?

Nov 15 '05 #5
Dan,

I would be happy to help.

glen lee jones AT comcast.net ( no spaces )

I'll try to respond as quick as I can.
--
Glen Jones MCSD

"Dan K." <da****@oxigem.com> wrote in message
news:cf**************************@posting.google.c om...
sorry for the late answer ... was on holiday the last weeks :)

problem still active ...

at my view its not the implemententation of the of the keydown event
cause this implementation was only a test to check if DEL Key fires an
event.
the naturally DEL Function (delete content) dont do his job on this
control. the test should only show why.
but its still not clear for me. any further idea ?

glen can i still send you the source of this control to check ?

Nov 15 '05 #6
i´ll give it a try tomorrow ... today im to tired :)
i will reporting whats happen ... strange is also that the DEL key
with his standard delete function works if i inialize the control new
... without content ... if i load data into the txtboxes so the arent
"new" the DEL key does nothing.
"José Joye" <jo*******@KILLTHESPAMSbluewin.ch> wrote in message news:<el*************@TK2MSFTNGP12.phx.gbl>...
I may be out of topic. I do not have the history of this message. However,
If you are playing with a form, what about this:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData==Keys.Delete)
{
MessageBox.Show("Delete pressed!");
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}

José
"Dan K." <da****@oxigem.com> wrote in message
news:cf**************************@posting.google.c om...
sorry for the late answer ... was on holiday the last weeks :)

problem still active ...

at my view its not the implemententation of the of the keydown event
cause this implementation was only a test to check if DEL Key fires an
event.
the naturally DEL Function (delete content) dont do his job on this
control. the test should only show why.
but its still not clear for me. any further idea ?

glen can i still send you the source of this control to check ?

Nov 15 '05 #7
seems that José´s method is a good start to solve this problem ...
with his code snippet the box reacts to the DEL key. with my code
posted above there was no event / no msgbox. so i must only find a way
to check via the msg.HwND which box fires this event and than i should
delete content .. or ?

@glen

only the control source enough ? cause project is to big to send all
"Glen Jones MCSD" <gl********@mailhot.com> wrote in message news:<a6********************@comcast.com>...
Dan,

I would be happy to help.

glen lee jones AT comcast.net ( no spaces )

I'll try to respond as quick as I can.
--
Glen Jones MCSD

"Dan K." <da****@oxigem.com> wrote in message
news:cf**************************@posting.google.c om...
sorry for the late answer ... was on holiday the last weeks :)

problem still active ...

at my view its not the implemententation of the of the keydown event
cause this implementation was only a test to check if DEL Key fires an
event.
the naturally DEL Function (delete content) dont do his job on this
control. the test should only show why.
but its still not clear for me. any further idea ?

glen can i still send you the source of this control to check ?

Nov 15 '05 #8
now i have this code and it works

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData==Keys.Delete)
{
SetWindowText(msg.HWnd.ToInt64( ), String.Empty);
return true;
} return base.ProcessCmdKey (ref msg, keyData);
}
content of the focused box will be deleted if i hit the DEL Key. Not a
solution but a first workaround ... maybe Glen could say more :)
Nov 15 '05 #9
Dan K.

I went back and looked at your original post. I can also understand having
to much code to post. So let me see if I can help.

First, the ProcessCmdKey method example that was posted will work but
becareful. That method is form level not just for a text box.

Ok, the first thing to check is if the Form.KeyPreview property is true and
you intercept the delete key and then set the KeyEventArgs.Handled property
to true, the event will never get called.

The Next thing to check is that the Initialization of the Textbox includes
the following line:
this.textBox1.KeyDown += new KeyEventHandler( this.textBox1_KeyDown );

If that is there every thing should work.

I have posted the code that works at the end of this post.

Hope this helps.
--
Glen Jones MCSD

Sample Code
**************************************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace CWinTest
{
public class Form1 : System.Windows.Forms.Form
{
private TextBox textBox1;
private Container components = null;

public Form1()
{
// Required for Windows Form Designer support
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
if (components != null)
components.Dispose();

base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.textBox1 = new TextBox();
this.SuspendLayout();
// textBox1
this.textBox1.Location = new Point(24, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new Size(192, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
this.textBox1.KeyDown += new KeyEventHandler(
this.textBox1_KeyDown );
// Form1
this.AutoScaleBaseSize = new Size(5, 13);
this.ClientSize = new Size(292, 273);
this.Controls.AddRange(new Control[] { this.textBox1 } );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
switch( e.KeyCode )
{
case Keys.Delete :
MessageBox.Show("DEL Key!");

e.Handled = true;
break;
}
}
static void Main()
{
Application.Run(new Form1());
}
}
}
Nov 15 '05 #10

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

Similar topics

1
by: Todd Smith | last post by:
I've read about Browser Helper Objects and how they load in a dll with IE and can intercept messages and change things. I've got a neat idea for a change to the icq interface, but I don't want to...
1
by: zoltix | last post by:
Hi, I am beginner in JavaScript. I would like to intercept all click events on my document. I use this function for that document.onmousedown=click;. It works well. But I would like to...
1
by: Imran | last post by:
Hi, Please bear with me as I have only 1 weeks .NET experience. I am using VB.NET to write a stand-alone client application that connects to a Web service. I successfully send a request for a...
0
by: zoltix | last post by:
Hi, I am beginner in aspx. I would like to intercept all click events on my document. I use this function in javascipt for that document.onmousedown=click;. It works well. But I would...
0
by: xudeutsch | last post by:
My application has a directory \contrlol and under this directory the control aaa.dll (generated by another project) is put here. The aaa.dll as an object is used in the bbb .aspx file. When...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
8
by: RJ45 | last post by:
Hello, I am writing a shell in C. I need to intercept Signals like CTRL+C or CTRL+D and set to ignore them. This is on Unix, using gcc. my goal is to avoid users escaping the shell with SIGINT...
7
by: ADN | last post by:
Hi, I am creating a custom HTTPModule to intercept the request of when the user is attempting to retrieve a session variable. For instance, if I set a session variable in my code like so: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...

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.