c# - 剪贴板问题,列表中有几个问题
问题描述
我的问题
我有一个程序,列表中有很多问题。我想用剪贴板来回答这些问题。但是我的程序中有超过 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;
}
解决方案
这对我有用,所以我很确定有时你的两个条件之一没有得到满足。
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)
{
}
}
}
推荐阅读
- php - PHP/MYSQL INSERT INTO ON DUPLICATE KEY UPDATE 未按预期工作
- ios - UIImagePickerController 可以用来从文档目录中选择图片吗?
- linux - 如何安装 TCL 包 textutil、tdom 和 udp?
- go - net/http 传输超过 MaxConnsPerHost
- python - 如何在 Python 中只输入一个工作日的日期
- user-interface - 无法将自定义组件添加到 Intellij GUI 表单
- java - Android位置权限错误与null
- c# - 在 ASP.NET Core 应用程序中生成 ASP.NET 4.x 类型的 cookie
- java - 我们如何通过 java 从未知 XML 中获取所有节点名称
- sql - Hive:使用没有 LATERAL VIEW 的数组连接表爆炸