проблема с буфером обмена с несколькими вопросами в списке - PullRequest
0 голосов
/ 02 октября 2018

МОЯ ПРОБЛЕМА
У меня есть программа с большим количеством вопросов в списке.Я хочу получить ответ на эти вопросы в буфер обмена.Но у меня в программе более 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 голосов
/ 02 октября 2018

Это работает для меня, поэтому я уверен, что иногда одно из ваших двух условий не выполняется.

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

            }
        }
   } 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...