gpt4 book ai didi

c# - 确定 Windows 窗体应用程序中的插入模式

转载 作者:行者123 更新时间:2023-12-02 04:39:53 25 4
gpt4 key购买 nike

我想检查 C# Windows 窗体应用程序中 Insert 键的状态。这是最少的代码(不起作用;形成两个 RadioButtons):

using System;
using System.Windows.Forms;

using System.Windows.Input;
// Also added PresentationCore and WindowsBase refereneces

namespace InsertModeDemo1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
if (Keyboard.IsKeyToggled(Key.Insert))
radioButtonInsert.Checked = true;
else
radioButtonOverstrike.Checked = true;
}
}
}

最佳答案

尝试改用 Control.IsKeyLocked

private void Form1_Load(object sender, EventArgs e)
{
if (Control.IsKeyLocked(Keys.Insert))
radioButtonInsert.Checked = true;
else
radioButtonOverstrike.Checked = true;
}

引用文献:Control.IsKeyLocked

注意

The documentation says the method only works with CAPS LOCK, NUM LOCK, or SCROLL LOCK key only. But testing the method with Keys.Insert has proven that it also work for INSERT key.

关于c# - 确定 Windows 窗体应用程序中的插入模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com