modirforoosh
دوشنبه 06 شهریور 1396, 09:47 صبح
با سلام
من یه مشکلی دارم که امیدوارم اساتید کمک کنند
من یک صفحه دارم که باید یک اسم و کد در آن چاپ شود . از یک لیست باکس کدهای رکوردهای دیتابیس دریافت میشود و در یک حلقه در صفحه چاپ میشود . ولی الان مشکلی که دارم اینه که میخوام هر اسم وکد مربوط به هر رکورد در یک صفحه جداگانه چاپ شود . کد زیر را نوشتم اما همه در یک صفحه چاپ میشود .
private void button9_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
printDialog1.Document = pd;
if (printDialog1.ShowDialog()==DialogResult.OK)
{
pd.PrinterSettings = printDialog1.PrinterSettings;
pd.PrintPage += new PrintPageEventHandler(prtpage);
pd.Print();
}
}
private void prtpage(object sender, PrintPageEventArgs e)
{
int i, count;
count = listBox1.Items.Count;
for (i = 0; i < count; i++)
{
strformat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
CN.Open();
CM.Connection = CN;
CM.CommandText = "select * from bongah where id='" + listBox1.Items[i].ToString() + "'";
SqlDataAdapter DA2 = new SqlDataAdapter(CM.CommandText, CN);
DataTable DT2 = new DataTable();
DA2.Fill(DT2);
e.Graphics.DrawString(DT2.Rows[0][1].ToString(), f1, Brushes.Black, 750, 15, strformat);
e.Graphics.DrawString("کد : " + DT2.Rows[0][0].ToString(), f1, Brushes.Black, 750, 35, strformat);
CN.Close();
e.HasMorePages = true;
}
من یه مشکلی دارم که امیدوارم اساتید کمک کنند
من یک صفحه دارم که باید یک اسم و کد در آن چاپ شود . از یک لیست باکس کدهای رکوردهای دیتابیس دریافت میشود و در یک حلقه در صفحه چاپ میشود . ولی الان مشکلی که دارم اینه که میخوام هر اسم وکد مربوط به هر رکورد در یک صفحه جداگانه چاپ شود . کد زیر را نوشتم اما همه در یک صفحه چاپ میشود .
private void button9_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
printDialog1.Document = pd;
if (printDialog1.ShowDialog()==DialogResult.OK)
{
pd.PrinterSettings = printDialog1.PrinterSettings;
pd.PrintPage += new PrintPageEventHandler(prtpage);
pd.Print();
}
}
private void prtpage(object sender, PrintPageEventArgs e)
{
int i, count;
count = listBox1.Items.Count;
for (i = 0; i < count; i++)
{
strformat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
CN.Open();
CM.Connection = CN;
CM.CommandText = "select * from bongah where id='" + listBox1.Items[i].ToString() + "'";
SqlDataAdapter DA2 = new SqlDataAdapter(CM.CommandText, CN);
DataTable DT2 = new DataTable();
DA2.Fill(DT2);
e.Graphics.DrawString(DT2.Rows[0][1].ToString(), f1, Brushes.Black, 750, 15, strformat);
e.Graphics.DrawString("کد : " + DT2.Rows[0][0].ToString(), f1, Brushes.Black, 750, 35, strformat);
CN.Close();
e.HasMorePages = true;
}