我有一个简单的 Windows 窗体:“消息”文本框具有 Enter 和 Leave 事件,允许用户仅在该字段上输入另一种语言的文本。“发送”按钮发送表单内容。用户填写 Message 并单击 Send 后,Textbox 的 Leave 事件会阻止按钮的 Click 事件触发。我需要两个处理程序来运行。
以下是相关代码:
private void Message_Enter(object sender, EventArgs e)
{
inputLang = InputLanguage.CurrentInputLanguage;
foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
{
if (lang.LayoutName == "United States-International")
{
InputLanguage.CurrentInputLanguage = lang;
break;
}
}
}
private void Message_Leave(object sender, EventArgs e)
{
InputLanguage.CurrentInputLanguage = inputLang;
}
private void Send_Click(object sender, EventArgs e)
{
string dest = ServerList.Text;
string msg = Message.Text;
if (dest.Length == 0 || msg.Length == 0 )
{
Log("Fill the destination server and the message");
return;
}
if (context.SendMessage(dest, msg))
{
if (!ServerList.Items.Contains(dest))
{
ServerList.Items.Add(dest);
}
}
else
{
if (ServerList.Items.Contains(dest))
{
ServerList.Items.Remove(dest);
}
}
}