Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi i am a newbie i am using vs 2010. I have a windows form with a background image. And i have some label on that
I want to stamp that form with labels on that.
How can i do that?
I have seached a lot but. but i am confused how to do that as there are so man tools i.ei dont know what is this all thing but how can i stamp a form which labels on it?

Thanks in advance
Posted
Updated 16-Dec-12 18:00pm
v2

The easiest way is to use the PrintForm component from VB powerpacks: it's only a couple of lines of code. http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.printing.printform.aspx[^]

But you will get better results if you use a PrintDocument - it's a bit more to get your head around, but it produces a much, much more flexible and generally better result: http://msdn.microsoft.com/en-us/library/6he9hz8c.aspx[^]

Both of the links provide an example.

[edit]Typo: PrintDocuiment for PrintDocument - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
sariqkhan 15-Nov-12 8:00am    
what is the diffrence between vb's printform and vs's printdocument?
if i have a small scale form. means it does only have a photo and labels on it so which method you will prefer? vb or vs?
OriginalGriff 15-Nov-12 8:19am    
I would always go with PrintDocument - it takes a bit more work, =but you get a better result.
shaikh-adil 15-Nov-12 8:16am    
i am also doing this since one week that article is dumb. the code is not correct i think.
this is my code which is copied from that website using print document
there is some error
public partial class Form1 : Form
{
public Form1()
{

private Button printButton = new Button();
private PrintDocument printDocument1 = new PrintDocument();

public Form1()
{
printButton.Text = "Print Form";
printButton.Click += new EventHandler(printButton_Click);
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);//here is the error that "Ambiguity between 'printing.Form1.printDocument1' and 'printing.Form1.printDocument1'
this.Controls.Add(printButton);
}

void printButton_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocument1.Print(); // here is the error that "Ambiguity between 'printing.Form1.printDocument1' and 'printing.Form1.printDocument1'
}


Bitmap memoryImage;

private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}

private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}



public static void Main()
{
Application.Run(new Form1());
}
}
}



public static void Main()
{
Application.Run(new Form1());
}
OriginalGriff 15-Nov-12 8:22am    
Somehow, you have two objects called printDocument1 in your form - which is not easy to do, unless you have added one to the form as a control at design time, and added one via the line
private PrintDocument printDocument1 = new PrintDocument();
near the top of your code. If you have, then remove one of them - and I suspect you want to add the Button via the designer as well, or it won't get displayed! :laugh:
shaikh-adil 15-Nov-12 9:02am    
sorry i have solved but i dont have printer istalled. what type of output i will get??
if i want only the picturebox and there is label on that picturebox to be printed so how to do that?
i dont want whole form if the close minimize button and maximize button will be printing on that page
 
Share this answer
 
Comments
sariqkhan 15-Nov-12 9:10am    
but i dont have printer istalled. what type of output i will get?? if i want only the picturebox and there is label on that picturebox to be printed so how to do that? i dont want whole form if the close minimize button and maximize button will be printing on that page
also asked by adil
shaikh-adil 17-Nov-12 6:54am    
how to edit the form to print only the picture box? and labels on that form

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