I've searched everywhere for an answer to my problem. Everything I have found refers to something totally different than what I'm trying to do. I'm going to try writing up my problem here and maybe someone can give me a good solution.
1. I have a windows application with many winform objects to handle printing each with a progress bar and label on it. The winform is written in vb.net. My desktop application, which is written in vb.net, has many forms that generate reports. They all have the same basic premise of having report criteria controls as well as a progress bar and label.
2. I create a report that calls a method in a dll. The dll uses the PrintDocument class to create the actual report. That code is written in C#.
3. I have a special class that is located in the printing dll that is accessible from the desktop application. Among the things in that class are places for the progressbar and label.
4. During the printing of the report, I update the progress bar once per each loop through the data set.
The problem is I can't make the changes of the progressbar update to be seen in real time. It seems that the only time it does visually change is if I have to leave the print handler as I go from page to page. That tells me that this code isn't processing in real time. In fact, if I set a breakpoint right at the end of the updateProgressBar() and run the app, the progressbar does update. Of course, I have to keep hitting F5 to advance. So I need to find a way to make it happen during the print loop. I believe that is where the backgroundworker stuff comes in. However, I have no idea how to make that kind of code, so could use some serious help.
Here are some code snippets:
oPD = new xxxPRINTING.pdCommon(); // special object that contains many printing parameters and functions...
// including:
public void updateProgressBar ( ProgressBar pBar, System.Windows.Forms.Label lblCaption, int numRecs, int numCurrentRec )
{
if ( pBar != null )
{
// pBar.Increment (1);
pBar.PerformStep ();
pBar.Update (); // things to do to try to force the updated progressbar show...
pBar.Refresh ();
if ( lblCaption != null ) lblCaption.Text = String.Format ( "Printing record {0} of {1}", numCurrentRec.ToString(), numRecs.ToString() );
System.Windows.Forms.Application.DoEvents();
} // <--- if I set a breakpoint here, then the progressbar updates with show. If I don't break here, the displayed progressbar is haphazard at best.
}
Print handler setup:
pD.PrintPage += new PrintPageEventHandler ( pDPrintReport );
pD.Print();
pD.PrintPage -= new PrintPageEventHandler ( pDPrintReport );
Printing loop. This code is found in the print event handler "pDPrintReport" setup above:
for ( ; currentMember < numRecs; currentMember++ )
{
oPD.updateProgressBar ( localPrinterSettings.pBar, localPrinterSettings.lblCaption, numRecs, currentMember + 1 );
.
.
.
yPos += oPD.lineHeight;
if (yPos >= BottomOfPage)
break;
}
// When I get here, it means that x number of records have peen printed and the veretical position has gone base the logical end-of-page.
// The progressbar DOES update when I get here...
if (currentMember >= numRecs )
{
e.HasMorePages = false;
}
else
{
currentMember++;
}
Thanks in advance,
Jerry
Jerry Scannell
1. I have a windows application with many winform objects to handle printing each with a progress bar and label on it. The winform is written in vb.net. My desktop application, which is written in vb.net, has many forms that generate reports. They all have the same basic premise of having report criteria controls as well as a progress bar and label.
2. I create a report that calls a method in a dll. The dll uses the PrintDocument class to create the actual report. That code is written in C#.
3. I have a special class that is located in the printing dll that is accessible from the desktop application. Among the things in that class are places for the progressbar and label.
4. During the printing of the report, I update the progress bar once per each loop through the data set.
The problem is I can't make the changes of the progressbar update to be seen in real time. It seems that the only time it does visually change is if I have to leave the print handler as I go from page to page. That tells me that this code isn't processing in real time. In fact, if I set a breakpoint right at the end of the updateProgressBar() and run the app, the progressbar does update. Of course, I have to keep hitting F5 to advance. So I need to find a way to make it happen during the print loop. I believe that is where the backgroundworker stuff comes in. However, I have no idea how to make that kind of code, so could use some serious help.
Here are some code snippets:
oPD = new xxxPRINTING.pdCommon(); // special object that contains many printing parameters and functions...
// including:
public void updateProgressBar ( ProgressBar pBar, System.Windows.Forms.Label lblCaption, int numRecs, int numCurrentRec )
{
if ( pBar != null )
{
// pBar.Increment (1);
pBar.PerformStep ();
pBar.Update (); // things to do to try to force the updated progressbar show...
pBar.Refresh ();
if ( lblCaption != null ) lblCaption.Text = String.Format ( "Printing record {0} of {1}", numCurrentRec.ToString(), numRecs.ToString() );
System.Windows.Forms.Application.DoEvents();
} // <--- if I set a breakpoint here, then the progressbar updates with show. If I don't break here, the displayed progressbar is haphazard at best.
}
Print handler setup:
pD.PrintPage += new PrintPageEventHandler ( pDPrintReport );
pD.Print();
pD.PrintPage -= new PrintPageEventHandler ( pDPrintReport );
Printing loop. This code is found in the print event handler "pDPrintReport" setup above:
for ( ; currentMember < numRecs; currentMember++ )
{
oPD.updateProgressBar ( localPrinterSettings.pBar, localPrinterSettings.lblCaption, numRecs, currentMember + 1 );
.
.
.
yPos += oPD.lineHeight;
if (yPos >= BottomOfPage)
break;
}
// When I get here, it means that x number of records have peen printed and the veretical position has gone base the logical end-of-page.
// The progressbar DOES update when I get here...
if (currentMember >= numRecs )
{
e.HasMorePages = false;
}
else
{
currentMember++;
}
Thanks in advance,
Jerry
Jerry Scannell