Member 8727118 Ответов: 1

Printpreview в C# не показывает повышенные значения панели?


I am stucked in a problem please help me...

i want to print a page with 5 column values values from database. ALthough I navigated to the second record on my form but pROBLEM IS on printpreview it shows values of first record why? Here is my code.

What I have tried:

Here is my code:

<pre> public void NavigateRecords()
        {
            dr = ds.Tables[0].Rows[increment];
            lblName.Text = dr["Name"].ToString();
            lbltbPostAPpliedFor.Text = dr["PostAppliedFor"].ToString();
            lblCNIC.Text = dr["SomeValue2"].ToString();

            rollNo = dr["SomeValue"].ToString();
            char[] arrRollNo = rollNo.ToString().ToCharArray();
            s = string.Join("   ", arrRollNo);

            lblRollNo.Text = s;
            //for paper vode

            paperCode = dr["PaperCode"].ToString();
            char[] arrPaperCode = paperCode.ToString().ToCharArray();
            s2 = string.Join("   ", arrPaperCode);
            lblPaperCode.Text = s2;
            if (ds.Tables[0].Rows.Count > 0)
            {
                MemoryStream ms = new MemoryStream((byte[])ds.Tables[0].Rows[increment]["candidate_Photo"]);
                pictureBox1.Image = new Bitmap(ms);
            }
        }

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{

//NavigateRecords();
e.Graphics.PageUnit = GraphicsUnit.Document;
printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

foreach (Control ctrl in panel1.Controls)
{
// if ( ctrl.GetType.ToString().Contains("TextBox") {
e.Graphics.DrawString(ctrl.Text.ToString(), new Font("Arial", 12), Brushes.Black, ctrl.Location.X * 3, ctrl.Location.Y * 3);
e.Graphics.DrawRectangle(Pens.Transparent, 0, 0, 50, 50);
e.Graphics.DrawRectangle(Pens.Transparent, 2431, 3457, 50, 50);
Point p = new Point(1000, 1500);
//e.Graphics.DrawImage(pictureBox2.Image, p);


SolidBrush b = new SolidBrush(Color.Black);
int x, y;

//for firt digit


if (index1 == 0)
{

x = 1562;
y = 522;
e.Graphics.FillEllipse(b, x, y, 53, 37);
}
}

private void btnPrint_Click(object sender, EventArgs e)
{
printDocument1.Print();
}

private void btnPreview_Click(object sender, EventArgs e)
{


// NavigateRecords();
printPreviewControl1.Document = printDocument1;

printPreviewControl1.Show();

}

1 Ответов

Рейтинг:
1

Perić Željko

Попробуйте прочитать эту статью :

Печать и предварительный просмотр нескольких страниц в C#[^]