Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The accept button and the multi-line textbox
Message
De
31/01/2007 11:01:51
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01190839
Message ID:
01190920
Vues:
14
Einar,

I haven't actually tried this, but I bet it's the same thing as capturing keystrokes in a DataGrid where you have to override the ProcessCmdKey() method in your "editbox" class (I have a separate class I call MyEditBox that is sub-classed from MyTextBox). I've posted this before for grids, try it and see if it works for an editbox too (I'm just pasting old stuff here, take what's appropriate):

Basically, you have to override the ProcessCmdKey method in your DataGrid sub-class ... see this article for more information:

http://www.codeproject.com/cs/database/DatabaseAcessWithAdoNet1.asp#Keystrokes

Here's an excerpt from the article with the code:

9. How to trap keystrokes (Up, Down, Esc, NumLock...) in the DataGrid

Like many users, I also looked for a method to catch the keystrokes in a DataGrid, and encountered it first in MSDN Library. So I decided to include it in the code so that users can make use of it. For most purposes, the standard KeyUp, KeyDown, and KeyPress events can capture and handle keystrokes. However, not all controls raise the standard KeyUp, KeyDown events for all keystrokes under all conditions. The DataGrid control is one of them.

If no data was assigned to the grid, the arrow keys (LEFT, RIGHT, UP, and DOWN) raise only the KeyUp event. If the DataGrid displays data, none of the standard keyboard events are raised for the navigation keys. The DataGrid is the control for which this feature is most frequently requested. You also can intercept key combinations, including CTRL and ALT. This technique does not capture the Print Screen key. In order to trap keystrokes in a Windows Forms control, you can override the ProcessCmdKey method ....
// Put this code in your Grid sub-class:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
	const int WM_KEYDOWN = 0x100;
	const int WM_SYSKEYDOWN = 0x104;

	if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
	{
		switch(keyData)
		{
			case Keys.Enter:
				MessageBox.Show("Enter");
				break;

			case Keys.Down:
				MessageBox.Show("Down");
				break;

			case Keys.Up:
				MessageBox.Show("Up");
				break;

			case Keys.NumLock:
				MessageBox.Show("NumLock");
				break;

			case Keys.Escape:
				MessageBox.Show("Escape");
				break;

		} 
	}

	return base.ProcessCmdKey(ref msg,keyData);
}
~~Bonnie




>Well the title says it all :)
>I have a form with a multi-line textbox on it and I have assigned an accept button to the form. So I start typing in my multi-line textbox and I press the enter key, because I want the text to start on a new line, but that is not what happens, instead the accept button's code fires and closes the form.
>
>What I have done in some applications so far is to not use the accept button form property when the form has a multi-line textbox on it, but I kinda like the accept button feature.
>
>Anywho any thoughts on the subject are welcome. Do you use the accept button property? What do you do when you have a multi-line textbox on the same form?
>
>Thanks,
>Einar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform