Link to home
Start Free TrialLog in
Avatar of guidway
guidwayFlag for United States of America

asked on

Printing a custom control

I created a user control that contains a couple of labels. I integrated the control into a project and now I need to print everything on this control (labels and an image). I've been experimenting with the graphics object but can't figure out how to print the entire control with all of its information. The most I can get to print is the bitmap background image of the control which is contained in a picture box. How do I print a custom control in .NET? thanks
ASKER CERTIFIED SOLUTION
Avatar of prakash_prk
prakash_prk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for printing use the following code
---------------------------------------

Image myIm;

ScreenCapture sd = new ScreenCapture();
myIm = sd.CaptureWindow(Handle);

PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

pd.Print();

private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
      e.Graphics.DrawImage(myIm,0,0,myIm.Width,myIm.Height);
      e.HasMorePages = false;
}
------------------------------------------------------------------------------------------

regards
prakash
Avatar of guidway

ASKER

I made a few slight modifications and was able to get your code working exactly as expected. thanks for your help!