【发布时间】:2015-07-23 18:05:01
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using Microsoft.VisualBasic;
namespace HelloWorld
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string filePathTEST = "";
public MainWindow()
{
InitializeComponent();
// Clearing text event handlers
textBox1.GotFocus += textBox1_GotFocus;
// Enter event handlers for textboxes
textBox1.KeyDown += new System.Windows.Input.KeyEventHandler(textBox1_KeyDown);
}
static void textBox1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//enter key is down
}
}
我在尝试运行上述代码时遇到的错误如下:
不能隐式转换类型 'System.Windows.Forms.KeyEventHandler' 到 'System.Windows.Input.KeyEventHandler'
然后我尝试将代码更改为 System.Windows.Input,然后我得到以下信息:
错误 1 'System.Windows.Input.KeyEventArgs' 不包含 'KeyCode' 的定义并且没有扩展方法 'KeyCode' 接受 'System.Windows.Input.KeyEventArgs' 类型的第一个参数可以是 找到(您是否缺少 using 指令或程序集引用?)
我这样做的全部意义在于,当我在文本框中按 Enter 键时,我想获取该文本框中的文本并用它填充某个文本文件,但我不知道该怎么做。
【问题讨论】: