July 28th, 2008, 04:24 AM
C# Controls: How do I activate the PrintDialog from a Toolstrip item?
Q: Whenever I show the PrintDialog from a Toolstrip button, using the UseExDialog property, I have to click the PrintDialog twice, before it gets activated, how can I fix this?
A: You should make use of a Delegate to handle the displaying of the PrintDialog, here is an example :
This is of course assumed that you have a PrintDialog and a Toolstrip ( with at least one button ) on the form, using their default names.
delegate DialogResult ShowThePrintDialog(); //Create Delegate
private void toolStripButton1_Click(object sender, EventArgs e)
ShowThePrintDialog printD = new ShowThePrintDialog(printDialog1.ShowDialog); //What the Delegate Must Do
this.BeginInvoke(printD); //Start The Delegate
Q: What is a Delegate?
A: More Information
Q: What does BeginInvoke do?
I have added 2 attachments.
The one Attachment ( WrongResult.zip ), demonstrates the behaviour of the PrintDialog, when using the UseExDialog property set to true. When you run the sample, you will see that you have to click the PrintDialog twice, as it is not automatically activated.
The second attachment, demonstrates how to overcome this issue.
Last edited by HanneSThEGreaT; May 19th, 2010 at 07:02 AM.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!