james james

james james

  • NA
  • 419
  • 29.7k

Validate Check box before printing

Aug 11 2017 12:16 PM
I have 3 checkboxes that at least one needs to be checked before printing. I have the check boxes linked to the Print button. when i click print a message box states to check one box. when i check the box nothing happens.
 
<div>private void btnPrint_Click(object sender, EventArgs e)
{
try
{
if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
{
MessageBox.Show("Please select one !");
}
}
catch (Exception ex)
{
printDocument1.PrintPage += printDocument1_PrintPage;
printDocument1.Print();
}
}
private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e)
{
try
{
e.PageSettings.Landscape = true;
Bitmap bm = new Bitmap(this.panel.Width, this.panel.Height);
panel.DrawToBitmap(bm, new Rectangle(0, 0, this.panel.Width, this.panel.Height));
e.Graphics.DrawImage(bm, 0, 0, bm.Width, bm.Height);
}
catch (Exception ex)
{
string s1 = ex.Message;
}
}
}
}<div>
 

Answers (8)