syntaxEditor.Print() doesn't do anything

SyntaxEditor for Windows Forms Forum

Posted 16 years ago by Michael Höhne
Version: 4.0.0276
Avatar
I want to add printing capabilities to my application and added buttons to the form showing the syntax editor. This button simply executes syntaxEditor.Print(true) but nothing happens when this line is run. There's a small delay, maybe some tenths of a seconds, but no print job is generated and no print dialog is shown.

The PrintPreview dialog works. Any idea what's missing? OS is Windows Server 2008 64-bit edition, DevEnv is Visual Studio 2008.

Thanks,
Michael

Comments (9)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Michael, if you are calling Print(true) then that executes code that shows a PrintDialog. It's working when we test it here. Put a breakpoint on your code to ensure you get to that statement in your code where you call Print(). Maybe you aren't actually hitting it.


Actipro Software Support

Posted 16 years ago by Michael Höhne
Avatar
I did that before. Put a breakpoint on the line and it is executed. No print dialog being shown though. That was the reason why I tried the PrintPreview method, which succeeded.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Our code is pretty simple, it just creates a standard .NET PrintDialog instance, sets a couple properties and shows it. Maybe see if you are able to do the same thing or not.


Actipro Software Support

Posted 16 years ago by Michael Höhne
Avatar
Thanks for your answer. The following code opens the print dialog:

PrintDialog dialog = new PrintDialog();
dialog.UseEXDialog = true;
dialog.ShowDialog(this);

The following does not work:

PrintDialog dialog = new PrintDialog();
dialog.ShowDialog(this);

I don't know why UseEXDialog must be set, but I'm investigating. Right now it seems a problem with the .NET Framework rather than your software.

Thanks
Michael
Posted 16 years ago by Michael Höhne
Avatar
I found the following in the remarks section of the PrintDialog.UseEXDialog Property in the Visual Studio 2008 documentation:

When this property is set to true, ShowHelp and ShowNetwork will be ignored as these properties were made obsolete for Windows 2000 and later versions of Windows. Also, The PrintDialog class may not work on AMD64 microprocessors unless you set the UseEXDialog property to true.

It indeed does work when setting UseEXDialog to true. However, I don't see a way to set this property on the Syntax Editor control. Would you mind trying your Print method on a 64-bit machine?
Posted 16 years ago by Michael Höhne
Avatar
I was able using the following workaround:

PrintDialog dialog = new PrintDialog();
dialog.UseEXDialog = true;
dialog.Document = this.syntaxEditorOldXml.PrintSettings.PrintDocument;

if (dialog.ShowDialog(this) == DialogResult.OK) {
dialog.Document.Print();
}
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks Michael, good find. That really is odd that the framework doesn't function correctly without that new setting on AMD 64 only. Anyhow we'll add the setting to true also in our code for the next build.


Actipro Software Support

Posted 16 years ago by Michael Höhne
Avatar
Just for your information: I have an Intel Core 2 Duo, which I wouldn't say is AMD64. But I have to use AMD64 installs on this machine, so it seems behaving the same.

And setting UseEXDialog = true introduces a new problem: the first click on the print dialog is ignored, because it doesn't have the focus. Seems a known problem and hopefully it's fixed in the .NET Framework soon.

That is quite a dilemma for you, so to be on the safe side, you could just add the UseEXDialog property to your own print settings. That way no one can blame you for a bug in the .NET Framework.

My final implementation uses the registry to check the processor type:

private void PrintDocument(SyntaxEditor editor) {

bool isAmd64 = false;
RegistryKey environment = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Session Manager\Environment");

if (environment != null) {
isAmd64 = ((string) environment.GetValue("PROCESSOR_ARCHITECTURE") == "AMD64");
}

if (isAmd64) {
PrintDialog dialog = new PrintDialog();
dialog.UseEXDialog = true;
dialog.Document = editor.PrintSettings.PrintDocument;

if (dialog.ShowDialog(this) == DialogResult.OK) {
dialog.Document.Print();
}
}

else {
editor.Print(true);
}
}

Hope it helps.

Cheers,
Michael
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Michael,

Thanks, what we'll do is add an overload to Print that lets you specify whether to use or not use the extended dialog.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.