首页 > 解决方案 > 剪贴板问题,列表中有几个问题

问题描述

我的问题
我有一个程序,列表中有很多问题。我想用剪贴板来回答这些问题。但是我的程序中有超过 50 个问题,有时我的列表中的一些问题没有得到回报,我该如何解决?

这是我的代码

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)
                //with foreach we go through all our questions

                {
                //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);
                    Clipboard.Clear();
                    return;
                }

标签: c#clipboard

解决方案


这对我有用,所以我很确定有时你的两个条件之一没有得到满足。

const int WM_DRAWCLIPBOARD = 36;
protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);

        //check if current operation is a clipboard
        if (m.Msg == WM_DRAWCLIPBOARD)
        {
            try
            {
                if (Clipboard.GetText() == "123")
                {
                    MessageBox.Show(Clipboard.GetText());
                    Clipboard.Clear();
                    return;
                }
            }
            catch(Exception e)
            {

            }
        }
   } 

推荐阅读