jjzjj

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

coder 2024-06-02 原文

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

如果是这样,您能否在您的回答中张贴一个使用示例文档链接

谢谢。

我所说的“流畅打字”指的是打字动画,它使光标在打字过程中滑动。

最佳答案

我没有 Office,所以我看不到该功能,但我前一阵子需要摆弄 RichTextBoxes 中的插入符号,并决定不值得为此付出努力。基本上你是一个人。 .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
                // (e.g. 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();
}

关于c# - 有什么方法可以将 MS Office Smooth Typing 集成到 C# 应用程序中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15327435/

有关c# - 有什么方法可以将 MS Office Smooth Typing 集成到 C# 应用程序中吗?的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  5. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  6. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  7. ruby - 将差异补丁应用于字符串/文件 - 2

    对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl

  8. Ruby 方法() 方法 - 2

    我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby​​-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco

  9. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  10. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

随机推荐