c# - 如何在事件处理程序 C# 之前阻止代码
问题描述
我正在寻找一种方法来阻止我的代码,直到运行事件处理程序。
我的代码如下:
private void extendBt_Click(object sender, EventArgs e)
{
DisplayPrompt("Select a Construction line (L) or Two point (P) to extend");
// I want this code is blocked here, then user must press on P or L to continue
this.KeyPress += new KeyPressEventHandler(keypressed);
if (key == "p")
{
// Method "P";
}
if (key == "l")
{
// Method "L";
}
else // If L or P aren't pressed => How to return to the select event on keyboard ?
}
解决方案
这似乎是一个基于 Windows 窗体的应用程序,基于KeyPressEventHandler
.
从用户界面设计 POV 来看,表单应该有一个RadioButton
或Combobox
多个用户可以做出选择。在此之前,禁用扩展按钮。
如果您想坚持这种方式,您将需要创建另一个表单并将选择控件放在那里。在按钮单击时,显示该 CustomForm 使用ShowDialog
,并且当用户选择时,基于此返回DialogResult
主表单。您可以为 P/L 选择是/否,然后进行相应的处理。
那时你根本不需要KeyPressEventHandler
。
推荐阅读
- django-rest-framework - 如何使用 django-rest-framework 获取 id 以通过 id 创建对象
- dart - 在 dart null 安全中暂停流
- php - 尝试在 Wordpress 中获取当前帖子的自定义帖子类型类别链接作为帖子的元数据
- php - 如何在上传到 Google Cloud 之前使用 PHP 计算文件的 MD5
- java - 如何注入 Git Credentials Provider 而不是从 bootstrap.yml 或 application.properties 中选择属性
- laravel - 如何在 iis7 中使用 laravel 路由
- php - 如何将 php 文件放入 div 类中?
- r - str_c 构建一个引号包裹的逗号分隔向量
- javascript - JavaScript 命令处理程序没有运行其他命令?
- json - 使用 bash 和 jq 并读取内容中包含 \n 的 json 文件