首页 > 解决方案 > 使用剪贴板选择句子的一部分而不是整个句子

问题描述

我想要我的程序而不是选择整个句子进行返回,如果复制它,部分句子也是可能的。

这是我的代码:

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);

    //check if current operation is a clipboard
    if (m.Msg == WM_DRAWCLIPBOARD)
    {
        //then we use a try catch block so if 
        //anything wrong happens in Clipboard.GetText() our program wont crash
        try
        {
            //with foreach we go through all our questions
            foreach (string question in questionList)
            {
                //and we check if clapboarded text is matches with our question
                if (Clipboard.GetText() == "When a computer is being assembled, which action can be taken to help eliminate cable clutter within a computer case?")
                {
                    notifyIcon1.Icon = SystemIcons.Exclamation;
                    notifyIcon1.BalloonTipTitle = "When a computer is being assembled, which action can be taken to help eliminate cable clutter within a computer case?";
                    notifyIcon1.BalloonTipText = "Install a modular power supply.*";
                    notifyIcon2.BalloonTipIcon = ToolTipIcon.Error;
                    notifyIcon1.ShowBalloonTip(100);
                    return;
                }

这就是问题:“在组装计算机时,可以采取哪些措施来帮助消除计算机机箱内的电缆杂乱?”

例如,如果您复制了以下内容,我想:当组装计算机时,

你得到相同的匹配和相同的通知

提前致谢

标签: c#windowsnotificationsclipboardnotify

解决方案


使用字符串方法 .Contains() 而不是相等比较。

if (Clipboard.GetText().Contains(yourString))

推荐阅读