8
Answers

Validate Check box before printing

james james

james james

7y
245
1
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)
1
Sam Hobbs

Sam Hobbs

NA 28.7k 1.3m 15y

I don't know how you are doing it so I don't know if there is an easier way. My guess is that there is not an easier way.
 
Note that often the "secret" to making a program that is easy to use is complex development. In other words, sometimes we must write complicated program to make one that is easy to use. Windows and .Net and database software such as SQL Server does a lot for us, but sometimes we must do some programming outselves.
 
My guess is that the code necessary for the search page is not difficult except for many details that need to be done.
 
Probably what I would do is to create a List<String> for each filter (selection criteria) then concatenate them all together as needed.
0
Vikas Ahlawat

Vikas Ahlawat

NA 577 661.6k 15y
Ya code is not difficult.
Thanks for your reply.