c# - if 语句,如何阻止程序继续读取第一个正确的 if 或 else if 语句
问题描述
在一个if else
语句中,程序也会读取第二个语句,即使它没有被使用。
第二条语句else if
包含一个指向用于打印的 WPF 表单的链接。即使因为使用了第一if
条语句而没有使用它,它仍然会提取 WPF 中的编码并将窗口窗体驻留在一个非常小的窗体中。
我需要阻止程序读取 else if 语句。
private void btnPrintPies_Click(object sender, EventArgs e)
{
if (txtPiesRecID == null || dgvPies.CurrentCell == null)
{
MessageBox.Show("There is no recipe to print", "Error");
this.tabControl1.SelectedTab = tabPage11;
}
else if (txtPiesRecID != null || dgvPies.CurrentCell != null)
{
SetValueForPrRecID = txtPiesRecID.Text;
PtRecipe window = new PtRecipe();
window.Show();
}
}
解决方案
因为 WPF 中的编码干扰了窗体,所以我将程序转换为没有窗体的 WPF。这解决了程序读取 else 部分并重置表单大小的问题。
推荐阅读
- python - 由于元组错误,无法访问多个嵌套字典中的字典
- javascript - ngx-translate 的 getTranslation 函数不监听 Observable 变化
- javascript - Typescript 中的 Lambda 行为怪异
- python - 绘制地理数据python
- python - 是否可以矢量化从源到熊猫数据框中的目标数组的距离计算?
- assembly - 汇编语言编程分割
- c++ - `inline` 和 `noexcept` 在 consteval 上下文中是多余的吗?
- neo4j - 在 macOS 上安装 Neo4j 社区服务器 V4.0.1
- python - 有序字典列表 - 从值中获取索引
- angular - Ionic 5 / Angular 9 服务不显示打字稿错误