作者:手机用户2502909227 | 来源:互联网 | 2024-10-11 17:04
引用
///
/// 输入法切ENG
///
public void ChangeENG()
{
WinAPI.PostMessage(WinAPI.HWND_BROADCAST, WinAPI.WM_INPUTLANGCHANGEREQUEST, IntPtr.Zero, WinAPI.LoadKeyboardLayout(WinAPI.en_US, WinAPI.KLF_ACTIVATE));//输入法切换为ENGLISH,扫码枪需要
}
///
/// 输入法切Chinese
///
public void ChangeChinese()
{
WinAPI.PostMessage(WinAPI.HWND_BROADCAST, WinAPI.WM_INPUTLANGCHANGEREQUEST, IntPtr.Zero, WinAPI.LoadKeyboardLayout(WinAPI.cn_ZH, WinAPI.KLF_ACTIVATE));//输入法切换为Chinese
}
类:
///
/// 输入法切换
///
public class WinAPI
{
[DllImport("user32.dll")]
public static extern bool PostMessage(int hhwnd, uint msg, IntPtr wparam, IntPtr lparam);
[DllImport("user32.dll")]
public static extern IntPtr LoadKeyboardLayout(string pwszKLID, uint Flags);
public static uint WM_INPUTLANGCHANGEREQUEST = 0x0050;
public static int HWND_BROADCAST = 0xffff;
public static string en_US = "00000409"; //英文
public static string cn_ZH = "00000804";
public static uint KLF_ACTIVATE = 1;
}
C#中FormClosing与FormClosed的区别详细解析
C#中,当窗口关闭时,它会引发两个事件:Closing 和 Closed。
Closing 在窗口关闭之前引发,它提供一种机制,可以通过这种机制来阻止窗口关闭。 系统会向Closing 事件处理程序传递一个 FormClosingEventArgs e,该参数实现 Boolean Cancel 属性,将该属性设置为 true 可以阻止窗口关闭。
DialogResult result = MessageBox.Show("你确定要关闭吗!", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
CloseDevice();
ClosePLC();
GC.Collect();
//this.Close();
this.Dispose();
e.Cancel = false;
}
else
{
e.Cancel = true;
}
在窗口真正关闭之前,会引发 Closed,这时无法阻止窗口关闭。
private void Form1_FormClosed(object sender, FormClosingEventArgs e)
{
Application.Exit();
}