c# - 中键复制并在复制时删除选择
问题描述
除了 CTRL-C 之外,我希望您能够在我的程序中选择要复制的文本,以及自动复制它。所以举例。如果我选择“这个”,那么它会自动将其复制到中键。到目前为止,这是我的代码。我一直在查看中间点击事件,但我不知道如何调用它。我会喜欢它作为 if 语句
这是我的代码:
private void GetAnswer(string clipboardText)
{
//Loop through all questions and answers
foreach (question q in questionList)
{
//If we have found an answer that is exactly the same show an Notification
//Startwith zoekt naar alle vragen die matchen vanaf het begin van de zin
//en Endwith alle vragen die matchen vanaf het eind van de zin
if (q._question.StartsWith(clipboardText) || q._question.EndsWith(clipboardText))
{
ShowNotification(q._question, q._answer);
break;
}
}
}
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)
{
GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
}
}
}
解决方案
我认为解决方案是处理表单的 KeyPress 事件。示例代码可能如下所示:
private void form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar==';')
{
//call whatever u want here
}
}
private void form1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//do whatever u want
}
}
推荐阅读
- c# - 多个 webapi 的 IIS 重定向问题
- authentication - 为 xampp phpmyadmin 设置登录选项的问题
- ios - 在 UITableViewCell 中将隐藏设置为 false 后,辅助功能检查器看不到 UIImageView
- math - 一组点的 k 聚类的可能组合数
- geoserver - 是gt mongodb源代码设置文档位置
- java - 我想用这个 aria-hidden="true" 自动处理活动的非活动按钮
- java - 需要使用浏览器缓存检查用户是否登录 | 硒Java
- javascript - 反应中的切换菜单仅响应第一次单击
- python - Google 电子表格到 Google Drive 中的 CSV
- sql - 如何在 pl/sql 游标中生成动态 where 条件