首页 > 解决方案 > 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();
    }
}

标签: c#winforms

解决方案


因为 WPF 中的编码干扰了窗体,所以我将程序转换为没有窗体的 WPF。这解决了程序读取 else 部分并重置表单大小的问题。


推荐阅读