剪贴板。使用计时器清除2个不同的时间无效C#

剪贴板。使用计时器清除2个不同的时间无效C#,c#,if-statement,timer,clipboard,C#,If Statement,Timer,Clipboard,我正在制作一个剪贴板应用程序,在这个应用程序中,我的程序必须能够粘贴列表中的问题和总和。现在我想要,如果我复制一个总和,结果可以粘贴10秒。我列表中的问题只能粘贴1秒。目前它只适用于我列表中的问题。该计时器称为DeleteQuestionTimer。现在需要另一个名为sumdeteCopyTimer的计时器,以确保可以将总和的结果粘贴到这段代码中10秒 clipboardText = clipboardText.Replace(',', '.'); //de regex voor de ope

我正在制作一个剪贴板应用程序,在这个应用程序中,我的程序必须能够粘贴列表中的问题和总和。现在我想要,如果我复制一个总和,结果可以粘贴10秒。我列表中的问题只能粘贴1秒。目前它只适用于我列表中的问题。该计时器称为
DeleteQuestionTimer。
现在需要另一个名为
sumdeteCopyTimer
的计时器,以确保可以将总和的结果粘贴到这段代码中10秒

clipboardText = clipboardText.Replace(',', '.');

//de regex voor de operator
var regex = new Regex(@"^(?<lhs>\d+(?:[,.]{1}\d)*)[ ]*(?<operator>[+\-\:x\%])[ ]*(?<rhs>\d+(?:[,.]{1}\d)*)$");
Match match = regex.Match(clipboardText);

if (!match.Success)
    return; // not valid form (a + b)

//de operators
Dictionary<string, Func<double, double, double>> binaryOperators 
= new Dictionary<string, Func<double, double, double>>()
{
    { "+", (a, b) => a + b},
    { "x", (a, b) => a * b },
    { "-", (a, b) => a - b },
    { "%", (a, b) => a / b * 100 },
    { ":", (a, b) => b == 0 ? double.NaN : a / b },
};

var lhs = double.Parse(match.Groups["lhs"].Value, CultureInfo.InvariantCulture);
var rhs = double.Parse(match.Groups["rhs"].Value, CultureInfo.InvariantCulture);
var answer = binaryOperators[match.Groups["operator"].Value](lhs, rhs);

System.Windows.Forms.Clipboard.SetText(answer.ToString());
//Kopieert het resultaat van de som in het clipboard
//De timer zorgt ervoor dat het resultaat van de som naar x aantal seconde niet meer te plakken is
// Laat antwoord zien
ShowNotification(clipboardText, answer.ToString());
clipboardText=clipboardText.Replace(',',');
//de regex voor de运算符
var regex=new regex(@“^(?\d+(?:[,.]{1}\d)*)[]*(?[+\-\:x\%])[]*(?\d+(?:[,.]{1}\d)*)$”;
Match=regex.Match(剪贴簿文本);
如果(!match.Success)
返回;//无效表格(a+b)
//de运算符
字典二进制运算符
=新字典()
{
{“+”,(a,b)=>a+b},
{“x”,(a,b)=>a*b},
{-”,(a,b)=>a-b},
{“%”,(a,b)=>a/b*100},
{“:”,(a,b)=>b==0?double.NaN:a/b},
};
var lhs=double.Parse(match.Groups[“lhs”].Value,CultureInfo.InvariantCulture);
var rhs=double.Parse(match.Groups[“rhs”].Value,CultureInfo.InvariantCulture);
var answer=binaryOperators[match.Groups[“operator”].Value](左、右);
System.Windows.Forms.Clipboard.SetText(answer.ToString());
//Kopieert在剪贴板中显示van de som的结果
//这是一个非常好的结果,因为这是一个非常好的结果
//Laat antwoord zien
ShowNotification(剪贴簿文本,answer.ToString());
所以我想要的是,总和的结果可以粘贴10秒,复制给我的问题列表的结果可以粘贴1秒

这是我的完整代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;

namespace it
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //Invoke a clipboard monitor
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);

        private IntPtr _ClipboardViewerNext;

        //Make some global variables so we can access them somewhere else later
        //This will store all Questions and Answers
        //In here will be the Questions and Answers
        List<question> questionList = new List<question>();
        private object result;

        // Demonstrates SetText, ContainsText, and GetText.



        private void Form1_Load(object sender, EventArgs e)
        {
            //Set our application as a clipboard viewer
            _ClipboardViewerNext = SetClipboardViewer(Handle);

            //Add question/answer to list
            question newQuestion = new question("What is the capital of the Netherlands?", "Amsterdam");
            questionList.Add(newQuestion);

        }

        private void GetAnswer(string clipboardText)
        {
            //Loop through all questions and answers//
            foreach (question q in questionList)
            {
                if (q._question.StartsWith(clipboardText) || q._question.EndsWith(clipboardText))
                {
                    ShowNotification(q._question, q._answer);
                    break;
                }
            }
            clipboardText = clipboardText.Replace(',', '.');
            //de regex voor de operator
            var regex = new Regex(@"^(?<lhs>\d+(?:[,.]{1}\d)*)[ ]*(?<operator>[+\-\:x\%])[ ]*(?<rhs>\d+(?:[,.]{1}\d)*)$");
            Match match = regex.Match(clipboardText);
            if (!match.Success)
                return; // not valid form (a + b)
                        //de operators
            Dictionary<string, Func<double, double, double>> binaryOperators = new Dictionary<string, Func<double, double, double>>()
            {

               { "+", (a, b) => a + b},
               { "x", (a, b) => a * b },
               { "-", (a, b) => a - b },
               { "%", (a, b) => a / b * 100 },
               { ":", (a, b) => b == 0 ? double.NaN : a / b },
        };
            var lhs = double.Parse(match.Groups["lhs"].Value, CultureInfo.InvariantCulture);
            var rhs = double.Parse(match.Groups["rhs"].Value, CultureInfo.InvariantCulture);
            var answer = binaryOperators[match.Groups["operator"].Value](lhs, rhs);
            System.Windows.Forms.Clipboard.SetText(answer.ToString());
            //Kopieert het resultaat van de som in het clipboard
            //De timer zorgt ervoor dat het resultaat van de som naar x aantal seconde niet meer te plakken is
            // Laat antwoord zien
            ShowNotification(clipboardText, answer.ToString());
        }

        private void ShowNotification(string question, string answer)
        {
            notifyIcon1.Icon = SystemIcons.Exclamation;
            notifyIcon1.BalloonTipTitle = question;
            notifyIcon1.BalloonTipText = answer;
            notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
            notifyIcon1.ShowBalloonTip(1000);
        }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            {
                const int WM_DRAWCLIPBOARD = 0x308;
                if (m.Msg == WM_DRAWCLIPBOARD)
                {
                    // Kopieert en kijkt of het overeen komt met de list
                    DeleteQuestionTimer.Enabled = false;
                    var text = Clipboard.GetText(TextDataFormat.UnicodeText);
                    DeleteQuestionTimer.Interval = 5000;
                    DeleteQuestionTimer.Enabled = true;
                    // als je gekopieert hebt reset de clipboard en als je voor 5 minuten niet kopieert sluit het programma zich af
                    if (!string.IsNullOrEmpty(text))
                    {
                        InteractiveTimer.Enabled = false;
                        GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
                        InteractiveTimer.Interval = 300000; // reset the timer
                        InteractiveTimer.Enabled = true;   // and start it again
                    }
                }
            }
        }
        private void InteractiveTimer_Tick(object sender, EventArgs e)
        {
            this.Close();
        }
        //Deze timer zorgt ervoor dat het programa zich naar x aantal minuten zichzelf sluit

        private void DeleteQuestionTimer_Tick(object sender, EventArgs e)
        {
            DeleteQuestionTimer.Enabled = false;
            Clipboard.Clear();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
利用制度全球化;
使用System.Linq;
使用System.Runtime.InteropServices;
使用系统文本;
使用System.Text.RegularExpressions;
使用System.Threading.Tasks;
使用系统计时器;
使用System.Windows.Forms;
名称空间
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
//调用剪贴板监视器
[DllImport(“User32.dll”,CharSet=CharSet.Auto)]
公共静态外部IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
私有Intptru剪贴板ViewerNext;
//制作一些全局变量,以便我们以后可以在其他地方访问它们
//这将存储所有问题和答案
//下面是问题和答案
List questionList=新列表();
私有客体结果;
//演示SetText、ContainsText和GetText。
私有void Form1\u加载(对象发送方、事件参数e)
{
//将应用程序设置为剪贴板查看器
_ClipboardViewerNext=设置ClipboardViewer(句柄);
//将问题/答案添加到列表中
问题newQuestion=新问题(“荷兰的首都是什么?”,“阿姆斯特丹”);
问题列表。添加(新问题);
}
私有void GetAnswer(字符串剪贴板文本)
{
//循环浏览所有问题和答案//
foreach(问题列表中的问题q)
{
if(q.(q.question.StartsWith(clipboardText)| | q.(u question.EndsWith(clipboardText))
{
展示通知(问题、答案);
打破
}
}
剪贴簿文本=剪贴簿文本。替换(',',');
//de regex voor de运算符
var regex=new regex(@“^(?\d+(?:[,.]{1}\d)*)[]*(?[+\-\:x\%])[]*(?\d+(?:[,.]{1}\d)*)$”;
Match=regex.Match(剪贴簿文本);
如果(!match.Success)
return;//格式无效(a+b)
//de运算符
Dictionary binaryOperators=新字典()
{
{“+”,(a,b)=>a+b},
{“x”,(a,b)=>a*b},
{-”,(a,b)=>a-b},
{“%”,(a,b)=>a/b*100},
{“:”,(a,b)=>b==0?double.NaN:a/b},
};
var lhs=double.Parse(match.Groups[“lhs”].Value,CultureInfo.InvariantCulture);
var rhs=double.Parse(match.Groups[“rhs”].Value,CultureInfo.InvariantCulture);
var answer=binaryOperators[match.Groups[“operator”].Value](左、右);
System.Windows.Forms.Clipboard.SetText(answer.ToString());
//Kopieert在剪贴板中显示van de som的结果
//这是一个非常好的结果,因为这是一个非常好的结果
//Laat antwoord zien
ShowNotification(剪贴簿文本,answer.ToString());
}
私有void ShowNotification(字符串问题、字符串答案)
{
notifyIcon1.Icon=SystemIcons.感叹号;
notifyIcon1.balloodtiptitle=问题;
notifyIcon1.balloodtiptext=答案;
notifyIcon1.BALOTIPICON=工具提示错误;
notifyIcon1.showballoottip(1000);
}
受保护的覆盖无效WndProc(参考消息m)
{
基准WndProc(参考m);
{
常量int WM_DRAWCLIPBOARD=0x308;
如果(m.Msg==WM_)
{
//赫特·奥韦恩·科杰克特的科皮耶特·恩基杰克特符合名单
DeleteQuestionTimer.Enabled=false;
var text=Clipboard.GetText(TextDataFormat.UnicodeText);
DeleteQuestionTimer.Interval=5000;
DeleteQuestionTimer.Enabled=true;
//5分钟后重新设置剪贴板