Hi,
i have a form in which i have different labels and picture boxes is there any way i can get the print of it by pressing print button on d same page but ofcourse that button shouldn't b d part of that print
thnks

Dani AI

Generated

Short answer: hide the Print button, capture the form to an image, print that image, then restore the button. That avoids the button appearing on the printed page and is the simplest approach for a WinForms beginner. As hinted, there are components and articles out there, and since pointed out this is a C# thread, below is a compact C# pattern that works for labels and PictureBox controls (this is what most newbies need).

private void btnPrint_Click(object sender, EventArgs e)
{
    btnPrint.Visible = false;
    Application.DoEvents();

    Bitmap bmp = null;
    try
    {
        bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
        this.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
    }
    finally
    {
        btnPrint.Visible = true;
    }

    using (PrintDocument pd = new PrintDocument())
    {
        pd.PrintPage += (s, ev) =>
        {
            var rect = ev.MarginBounds;
            float scale = Math.Min((float)rect.Width / bmp.Width, (float)rect.Height / bmp.Height);
            ev.Graphics.DrawImage(bmp, rect.Left, rect.Top, (int)(bmp.Width * scale), (int)(bmp.Height * scale));
        };

        using (PrintPreviewDialog preview = new PrintPreviewDialog { Document = pd })
        {
            preview.ShowDialog();
        }
    }

    bmp.Dispose();
}

Notes and troubleshooting:

  • DrawToBitmap works well for standard WinForms controls (labels, PictureBox). It may not render some ActiveX or custom-rendered controls. If a control is not drawn, try Graphics.CopyFromScreen(this.PointToScreen(Point.Empty), Point.Empty, this.Size) — but that requires the form to be fully visible and not overlapped on screen.
  • Always hide the print button (or move it off-screen) before capture and use try/finally to guarantee it’s restored even on error.
  • Scale the bitmap to fit margins (shown above) to avoid clipping; for very long forms consider splitting content or rendering controls directly in PrintPage for sharper text and multi-page control.
  • Dispose Bitmaps and PrintDocument/dialogs to avoid memory leaks.

This addresses ’s need for a newbie-friendly solution while keeping the print button out of the output.

Recommended Answers

All 8 Replies

Not getting you....
do u want d print out of current form....


thnks man..
i just want to get the print of my form i have labels and picture box in my form isn't there any easy way as m newbie

But his doubt is regarding VB>net using C#

: no offense meant :) even if OP is moving from VB to C#, why give VB examples?

O sorry wrong link got posted.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.