ed.CurrentInputContext有误,请重新生成
时间: 2024-02-24 17:00:13 浏览: 73
ed.gridpak:响应式网格生成器
非常抱歉我的回答有误。在 AutoCAD 中,获取当前输入上下文的方式应该是使用 `Editor.GetInputState()` 方法,而不是 `Editor.CurrentInputContext` 属性。以下是修改后的示例代码:
```
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
public class InputLanguageSwitcher
{
[CommandMethod("SwitchInputLanguage")]
public static void SwitchInputLanguage()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
// 判断当前输入模式是否为命令行模式
if (ed.GetInputState().IsInputPending)
{
// 切换输入法为英文
System.Windows.Forms.InputLanguage.CurrentInputLanguage = System.Windows.Forms.InputLanguage.DefaultInputLanguage;
}
else
{
// 切换输入法为中文
System.Windows.Forms.InputLanguage.CurrentInputLanguage = System.Windows.Forms.InputLanguage.InstalledInputLanguages[0];
}
}
// 注册事件监听器,在文本框中输入内容时自动切换输入法
public InputLanguageSwitcher()
{
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
Application.DocumentManager.DocumentActivated += DocumentManager_DocumentActivated;
}
private void DocumentManager_DocumentActivated(object sender, DocumentCollectionEventArgs e)
{
e.Document.Editor.SuspendInputQueue();
e.Document.Editor.ImeModeChanged += Editor_ImeModeChanged;
e.Document.Editor.ResumeInputQueue();
}
private void Editor_ImeModeChanged(object sender, EventArgs e)
{
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
System.Windows.Forms.InputLanguage.CurrentInputLanguage = System.Windows.Forms.InputLanguage.InstalledInputLanguages[0];
}
}
```
再次感谢您的指正,希望这次的回答能够帮到您。
阅读全文