Reputation: 1
C# Print Document Prints Images Fine, But Then Stops Printing Images. Its not the ink because there are other smaller images on the page that print fine. Maybe its a memory thing. Also other programs with Print Documents without any images, print ok for about 5 executions. Then the program freezes with the messagebox "Printing page 1 of document".
private void printLabelBack_PrintPage(object sender, PrintPageEventArgs e)
{
for (int xy = 0; xy < 8; xy++)
{
changeRectangleLabel();
//
//
//
//IMAGE
//
addressYCoordinate = rectangleY;
addressXCoordinate = rectangleX + 25f;
Image imageRecipe6;
imageRecipe6 = Image.FromFile(@"C:\Users\Owner\source\repos\PackLabels\PackLabels\Images\logoImage32.jpg");
e.Graphics.DrawImage(imageRecipe6, addressXCoordinate, addressYCoordinate, imageWidth, imageHeight);
//
//IMAGE END
//
}
}
private void buttonBack_Click(object sender, EventArgs e)
{
GetRecipeInfo();
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Simplex;
pd.DefaultPageSettings.Landscape = true;
pd.PrintPage += printLabelBack_PrintPage;
pd.Print();
}
public void changeRectangleLabel()
{
if (currentRectangle == 1)
{
rectangleX = 35f;
rectangleY = 10f;
}
if (currentRectangle == 2)
{
rectangleX = 302f;
rectangleY = 10f;
}
if (currentRectangle == 3)
{
rectangleX = 569f;
rectangleY = 10f;
}
if (currentRectangle == 4)
{
rectangleX = 836f;
rectangleY = 10f;
}
if (currentRectangle == 5)
{
rectangleX = 35f;
rectangleY = 402f;
}
if (currentRectangle == 6)
{
rectangleX = 302f;
rectangleY = 402f;
}
if (currentRectangle == 7)
{
rectangleX = 567f;
rectangleY = 402f;
}
if (currentRectangle == 8)
{
rectangleX = 836f;
rectangleY = 402f;
}
}
It prints ok for some time, Then it freezes. Maybe its a memory problem, any large images, or lots of code with for loops and it freezes. I thought maybe it was the wrong type of visual studio, x86 when I needed x64. As some of the shared visual studio components are stored in program files (x86). So I uninstalled everything visual studio and installed a new visual studio 2022 x64. My computer has a x64 based processor. I've scaled back the code but with large images or lots of loops it freezes. Even in debug mode it doesn't even get to the Print Document. It just freezes with the messagebox saying "page 1 of document".
any help would be great.
Upvotes: 0
Views: 39