有什么办法可以将MS Office Smooth Typing集成到C#应用程序中吗?

在我看来,MS Office Smooth Typing是Office套件中一项非常创新的function,我想知道.NET Framework中的程序员是否可以使用此function,特别是C#语言。

如果是这样,您能否在答案中找到文档链接,也可能是一个用法示例

谢谢。

我不拥有Office,所以我无法看到这个function,但是我需要在前一段时间里使用RichTextBox中的插入符号,并认为它不值得付出努力。 基本上你是独立的。 没有来自.NET的辅助函数,但所有内容都由后备Win32控件处理。 你将很难战胜已经发生的事情。 并可能最终拦截窗口消息和许多丑陋的代码。

所以我的基本建议是:不要这样做。 至少对于像TextBox或RichTextBox这样的基本表单控件。 您可能有更多的运气试图从.NET内远程访问正在运行的办公室,但这是一个完全不同的蠕虫病毒。

如果你真的坚持要去SetCaretPos – 路线,这里有一些代码可以让你开始运行一个基本版本,你可以改进:

// import the functions (which are part of Win32 API - not .NET) [DllImport("user32.dll")] static extern bool SetCaretPos(int x, int y); [DllImport("user32.dll")] static extern Point GetCaretPos(out Point point); public Form1() { InitializeComponent(); // target position to animate towards Point targetCaretPos; GetCaretPos(out targetCaretPos); // richTextBox1 is some RichTextBox that I dragged on the form in the Designer richTextBox1.TextChanged += (s, e) => { // we need to capture the new position and restore to the old one Point temp; GetCaretPos(out temp); SetCaretPos(targetCaretPos.X, targetCaretPos.Y); targetCaretPos = temp; }; // Spawn a new thread that animates toward the new target position. Thread t = new Thread(() => { Point current = targetCaretPos; // current is the actual position within the current animation while (true) { if (current != targetCaretPos) { // The "30" is just some number to have a boundary when not animating // (eg when pressing enter). You can experiment with your own distances.. if (Math.Abs(current.X - targetCaretPos.X) + Math.Abs(current.Y - targetCaretPos.Y) > 30) current = targetCaretPos; // target too far. Just move there immediately else { current.X += Math.Sign(targetCaretPos.X - current.X); current.Y += Math.Sign(targetCaretPos.Y - current.Y); } // you need to invoke SetCaretPos on the thread which created the control! richTextBox1.Invoke((Action)(() => SetCaretPos(current.X, current.Y))); } // 7 is just some number I liked. The more, the slower. Thread.Sleep(7); } }); t.IsBackground = true; // The animation thread won't prevent the application from exiting. t.Start(); } 

将SetCaretPos与您自己的动画计时function一起使用。 创建一个新线程,根据先前的位置和新的所需位置插入插入符号的位置。