1

我想知道如何在未选中时隐藏收据中的复选框名称以下是我的代码:

richTextBox2.Visible = true;
tabControl1.Visible = false;
richTextBox2.Text = FirstName.Text + ' ' + Surname.Text +   (System.Environment.NewLine) +
FullAddress.Text + (System.Environment.NewLine) +
ContactNumber.Text + (System.Environment.NewLine) +
EmailAddress.Text + (System.Environment.NewLine) +
dob.Text +
(System.Environment.NewLine) +
"----------------------------------------------------------" +
(System.Environment.NewLine) +
textBox1.Text + (System.Environment.NewLine) +
textBox2.Text + (System.Environment.NewLine) +
textBox3.Text + (System.Environment.NewLine) +
"You have chosen to have a banner with the following text:" +
(System.Environment.NewLine) +
BannerText.Text + (System.Environment.NewLine) +
"at the price of " + label43.Text + (System.Environment.NewLine) +
"You have asked for the following accessories: " +
(System.Environment.NewLine) + MasksCB.Text+
(System.Environment.NewLine) + PartyCB.Text+
(System.Environment.NewLine) + CrackersCB.Text +
(System.Environment.NewLine) + HatsCB.Text+
(System.Environment.NewLine) + label18.Text;

HatsCB PartyCB CrackersCB 和 MasksCB 都是复选框。打印收据时,即使没有选中这些框,它们也是可见的。我想知道如何在未选中这些框时隐藏它们,并在收据中选中这些框时使它们可见。

4

1 回答 1

2

您可以像这样使用?: 运算符:

 "You have asked for the following accessories: " +
 (MasksCB.Checked  ? System.Environment.NewLine + MasksCB.Text : "") + 
 (PartyCB.Checked  ? System.Environment.NewLine + PartyCB.Text : "") + 
 ...

仅在选中复选框时才打印文本

于 2013-03-20T22:32:22.607 回答