csharp 这是KeyPressed e.Handled的LinqPad示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 这是KeyPressed e.Handled的LinqPad示例相关的知识,希望对你有一定的参考价值。

//You'll have to run this example in LinqPad as a C# program.
//Or put a class around the two global methods and change .Dump() calls to Console.WriteLine

void Main()
{
	var frm = new Form1();
	frm.Controls[0].KeyPress += keypressed_inMain;
	frm.ShowDialog();
}

//React to the Enter keypress
private void keypressed_inMain(Object o, KeyPressEventArgs e)
{
	if (e.Handled) {
		"Not Handled by Main".Dump();
		return;
	}
	if (e.KeyChar == (char)Keys.Return)
	{
		e.Handled = true;
	}
	"Handled by Main".Dump();
}

// Define other methods and classes here
public class Form1: Form
{
	public Form1()
	{
		// Create a TextBox control.
		TextBox tb = new TextBox();
		this.Controls.Add(tb);
		tb.KeyPress += new KeyPressEventHandler(keypressed);
	}

        //react to the Enter keypress
	private void keypressed(Object o, KeyPressEventArgs e)
	{
		if (e.Handled) {
			"Not Handled by Form".Dump();
			return;
		}
		
		if (e.KeyChar == (char)Keys.Return)
		{
			e.Handled = true;
		}
		"Handled by Form".Dump();
	}
}

以上是关于csharp 这是KeyPressed e.Handled的LinqPad示例的主要内容,如果未能解决你的问题,请参考以下文章

java中的KeyPressed事件

在 JavaFX 中为 TextField 设置 KeyPressed 事件

在JavaFX中为TextField设置KeyPressed事件

当我按下一个键时没有调用 keyPressed() 方法?

将keypressed与char进行比较

JTable keypressed 事件仅在按下的第一个键时触发