用剪贴板选择句子的一部分而不是整个句子

时间:2018-10-01 13:27:24

标签: c# windows notifications clipboard notify

我希望我的程序而不是选择整个句子来返回,如果复制了一部分句子,那也是可能的。

这是我的代码:

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;
                }

这是一个问题:“组装计算机时,可以采取什么措施来消除计算机机箱内的电缆混乱?”

例如,我想复制以下内容:组装计算机时,哪个

您将获得相同的比赛和相同的通知

预先感谢

1 个答案:

答案 0 :(得分:1)

使用字符串方法.Contains()代替相等比较。

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