PDA

View Full Version : مشکل درست کردن صفحە جدید در printpage



mariwan_blue
دوشنبه 08 اردیبهشت 1393, 01:45 صبح
با سلام و عرض ادب خدمت اساتید عزیز
امیدوارم کە بتونید کمکم کنید
من این کد رو نوشتم کە از داتابیس اطلاعات رو بگیرە و بعدش پرینت کنە ولی با درست کردن صفحە جدید مشکل دارم

public int h=210;
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) {

if (checkBox1.Checked == true)
{
for (int j = 0; j < dataGridView1.Rows.Count - 1; j++)
{



e.Graphics.DrawString(dataGridView1.Rows[j].Cells[8].Value.ToString().PadLeft(25), this.Font, b, 180, 82 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[9].Value.ToString().PadLeft(27), this.Font, b, 180, 102 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[5].Value.ToString(), this.Font, b, 245, 122 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[10].Value.ToString(), this.Font, b, 245, 142 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[6].Value.ToString(), this.Font, b, 180, 162 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[7].Value.ToString(), this.Font, b, 180, 182 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[3].Value.ToString(), this.Font, b, 390, 82 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[4].Value.ToString(), this.Font, b, 390, 102 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[5].Value.ToString(), this.Font, b, 390, 122 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[10].Value.ToString(), this.Font, b, 390, 142 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[6].Value.ToString(), this.Font, b, 400, 162 + (j * h));


e.Graphics.DrawString(dataGridView1.Rows[j].Cells[7].Value.ToString(), this.Font, b, 400, 182 + (j * h));





e.Graphics.FillRectangle(p, 0, 0 + (j * h), 310, 67);
e.Graphics.DrawString("وزارة التعلیم العالی ", this.Font, w, 220, 15 + (j * h));
e.Graphics.DrawString("و البحث العلمی ", this.Font, w, 230, 30 + (j * h));
e.Graphics.DrawString("جامعة کرکوک", this.Font, w, 10, 15 + (j * h));
e.Graphics.DrawString("کلیة العلوم", this.Font, w, 15, 30 + (j * h));
Image imag = Image.FromFile(@"C:\Users\Mariwan O.Ali\Desktop\IQ.PNG");
e.Graphics.DrawImage(imag, 120, 15 + (j * h), 50, 40);
e.Graphics.DrawString("هویة الطالب", this.Font, w, 120, 55 + (j * h));
e.Graphics.DrawString("العمید", this.Font, b, 80, 135 + (j * h));
// e.Graphics.DrawImage(Column2.Image, 40, 67 + (j * h), 55, 70);
e.Graphics.DrawRectangle(r, 0, 0 + (j * h), 310, 200);
e.Graphics.DrawString(":الاسم", this.Font, b, 280, 82 + (j * h));
e.Graphics.DrawString(":القسم", this.Font, b, 280, 102 + (j * h));
e.Graphics.DrawString(":صنف الدم", this.Font, b, 262, 122 + (j * h));
e.Graphics.DrawString(":رقم الهویة", this.Font, b, 262, 142 + (j * h));
e.Graphics.DrawString(":تاريخ الإصدار", this.Font, b, 245, 162 + (j * h));
e.Graphics.DrawString(":تاريخ النفاذ", this.Font, b, 257, 182 + (j * h));
e.Graphics.DrawRectangle(r, 340, 0 + (j * h), 300, 200);
e.Graphics.DrawString("Name:", this.Font, b, 340, 82 + (j * h));
e.Graphics.DrawString("Dept.:", this.Font, b, 340, 102 + (j * h));
e.Graphics.DrawString("Blood G:", this.Font, b, 340, 122 + (j * h));
e.Graphics.DrawString("ID No:", this.Font, b, 340, 142 + (j * h));
e.Graphics.DrawString("Issue Date:", this.Font, b, 340, 162 + (j * h));
e.Graphics.DrawString("Exp Date:", this.Font, b, 340, 182 + (j * h));
e.Graphics.FillRectangle(p, 340, 0 + (j * h), 300, 67);
e.Graphics.DrawString("Ministry of", this.Font, w, 560, 15 + (j * h));
e.Graphics.DrawString(" Higher Education", this.Font, w, 530, 30 + (j * h));
e.Graphics.DrawString("& Scientific Research", this.Font, w, 520, 45 + (j * h));
e.Graphics.DrawString("Kirkuk University", this.Font, w, 350, 15 + (j * h));
e.Graphics.DrawString("Collage of Science", this.Font, w, 348, 30 + (j * h));
e.Graphics.DrawImage(imag, 460, 15 + (j * h), 50, 40);

}




}
else
if (checkBox1.Checked == false)
{
int g = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[0].Value != null)
{
if ((Boolean)row.Cells[0].Value == true)
{
listBox1.Items.Add(row.Cells[3].Value.ToString());
listBox2.Items.Add(row.Cells[4].Value.ToString());
listBox3.Items.Add(row.Cells[5].Value.ToString());
listBox4.Items.Add(row.Cells[6].Value.ToString());
listBox5.Items.Add(row.Cells[7].Value.ToString());
listBox6.Items.Add(row.Cells[8].Value.ToString().PadLeft(25));
listBox7.Items.Add(row.Cells[9].Value.ToString().PadLeft(27));
listBox8.Items.Add(row.Cells[10].Value.ToString());

g++;
for (int j = 0; j < g; j++)
{


e.Graphics.DrawString(listBox6.Items[j].ToString(), this.Font, b, 180, 82 + (j * h));


e.Graphics.DrawString(listBox7.Items[j].ToString(), this.Font, b, 180, 102 + (j * h));


e.Graphics.DrawString(listBox3.Items[j].ToString(), this.Font, b, 245, 122 + (j * h));


e.Graphics.DrawString(listBox8.Items[j].ToString(), this.Font, b, 245, 142 + (j * h));


e.Graphics.DrawString(listBox4.Items[j].ToString(), this.Font, b, 180, 162 + (j * h));


e.Graphics.DrawString(listBox5.Items[j].ToString(), this.Font, b, 180, 182 + (j * h));


e.Graphics.DrawString(listBox1.Items[j].ToString(), this.Font, b, 390, 82 + (j * h));


e.Graphics.DrawString(listBox2.Items[j].ToString(), this.Font, b, 390, 102 + (j * h));


e.Graphics.DrawString(listBox3.Items[j].ToString(), this.Font, b, 390, 122 + (j * h));


e.Graphics.DrawString(listBox8.Items[j].ToString(), this.Font, b, 390, 142 + (j * h));


e.Graphics.DrawString(listBox4.Items[j].ToString(), this.Font, b, 400, 162 + (j * h));


e.Graphics.DrawString(listBox5.Items[j].ToString(), this.Font, b, 400, 182 + (j * h));






e.Graphics.FillRectangle(p, 0, 0 + (j * h), 310, 67);
e.Graphics.DrawString("وزارة التعلیم العالی ", this.Font, w, 220, 15 + (j * h));
e.Graphics.DrawString("و البحث العلمی ", this.Font, w, 230, 30 + (j * h));
e.Graphics.DrawString("جامعة کرکوک", this.Font, w, 10, 15 + (j * h));
e.Graphics.DrawString("کلیة العلوم", this.Font, w, 15, 30 + (j * h));
Image imag = Image.FromFile(@"C:\Users\Mariwan O.Ali\Desktop\IQ.PNG");
e.Graphics.DrawImage(imag, 120, 15 + (j * h), 50, 40);
e.Graphics.DrawString("هویة الطالب", this.Font, w, 120, 55 + (j * h));
e.Graphics.DrawString("العمید", this.Font, b, 60, 145 + (j * h));

e.Graphics.DrawRectangle(r, 0, 0 + (j * h), 310, 200);
e.Graphics.DrawString(":الاسم", this.Font, b, 280, 82 + (j * h));
e.Graphics.DrawString(":القسم", this.Font, b, 280, 102 + (j * h));
e.Graphics.DrawString(":صنف الدم", this.Font, b, 262, 122 + (j * h));
e.Graphics.DrawString(":رقم الهویة", this.Font, b, 262, 142 + (j * h));
e.Graphics.DrawString(":تاريخ الإصدار", this.Font, b, 245, 162 + (j * h));
e.Graphics.DrawString(":تاريخ النفاذ", this.Font, b, 257, 182 + (j * h));
e.Graphics.DrawRectangle(r, 340, 0 + (j * h), 300, 200);
e.Graphics.DrawString("Name:", this.Font, b, 340, 82 + (j * h));
e.Graphics.DrawString("Dept.:", this.Font, b, 340, 102 + (j * h));
e.Graphics.DrawString("Blood G:", this.Font, b, 340, 122 + (j * h));
e.Graphics.DrawString("ID No:", this.Font, b, 340, 142 + (j * h));
e.Graphics.DrawString("Issue Date:", this.Font, b, 340, 162 + (j * h));
e.Graphics.DrawString("Exp Date:", this.Font, b, 340, 182 + (j * h));
e.Graphics.FillRectangle(p, 340, 0 + (j * h), 300, 67);
e.Graphics.DrawString("Ministry of", this.Font, w, 560, 15 + (j * h));
e.Graphics.DrawString(" Higher Education", this.Font, w, 530, 30 + (j * h));
e.Graphics.DrawString("& Scientific Research", this.Font, w, 520, 45 + (j * h));
e.Graphics.DrawString("Kirkuk University", this.Font, w, 350, 15 + (j * h));
e.Graphics.DrawString("Collage of Science", this.Font, w, 348, 30 + (j * h));
e.Graphics.DrawImage(imag, 460, 15 + (j * h), 50, 40);

}


}
}
}


}




listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
listBox4.Items.Clear();
listBox5.Items.Clear();
listBox6.Items.Clear();
listBox7.Items.Clear();
listBox8.Items.Clear();


}

مشکل من فکر میکم حلقە for باشە