剪贴板问题,列表中有几个问题

时间:2018-10-02 08:45:02

标签: c# clipboard

我的问题
我有一个程序,列表中有很多问题。我想用剪贴板就这些问题获得回报。但是我的程序中有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;
                }

1 个答案:

答案 0 :(得分:1)

这对我有用,因此我可以确定有时候您的两个条件之一不满足。

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)
            {

            }
        }
   }