Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to print content of tabpage that is part of TabControl.

This is the way how I'm doing it:

C#
Bitmap MemoryImage;

    public Interview1()
    {
        InitializeComponent();
        printdoc1.PrintPage += new PrintPageEventHandler(printdoc1_PrintPage);
    }

public void GetPrintArea(TabPage pnl)
{
    MemoryImage = new Bitmap(pnl.Width, pnl.Height);
    pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height));
}
protected override void OnPaint(PaintEventArgs e)
{
    if (MemoryImage != null)
    {
        e.Graphics.DrawImage(MemoryImage, 0, 0);
        base.OnPaint(e);
    }
}
    void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
    {
        Rectangle pagearea = e.PageBounds;
e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 65) - (this.tabPage2.Width / 65  ), this.tabPage2.Location.Y);
    }

public void Print(TabPage pnl)
{      
    tabPage2 = pnl;
    GetPrintArea(pnl);
    previewdlg.Document = printdoc1;
    previewdlg.ShowDialog();
}



private void toolBtnPrint_Click(object sender, EventArgs e)
{
     Print(tabPage2);
}


This works perfect, but the problem is if tabpage have a scroll bars. In that case it is printed only visible area. How to manage to print all from tabpage regardless about visible area?
Posted
Comments
Bark Ups 20-Aug-14 20:48pm    
Maybe try to pass whole tab content to temporary place and print from there?
like new form with content as preview and print from there or just do it from hidden one?

or make tab area scrennshot than scroll down content and after taking all screenshots combine them to one file?
gggustafson 21-Aug-14 12:00pm    
Like the first sentence

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900