Bug in PrintPreviewDialog?

B

Bruce Wood

I had a devil of a time setting the Icon for a class I made that
inherits from PrintPreviewDialog. I noticed that someone else (post is
in microsoft.public.dotnet.languages.csharp) had this same question.

I created a new dialog:

public class WindowsPrintPreviewDialogExtended :
System.Windows.Forms.PrintPreviewDialog

When I bring this class up in Visual Studio in designer mode, it has
almost no properties. Just Document, UseAntiAlias,
(DynamicProperties), (Name), DrawGrid, GridSize, Locked, SnapToGrid,
Language, and Localizable. Many of the properties available for other
forms, in particular the whole WindowStyle group, don't show up.

Furthermore, when looking at code, typing "this." shows the
Intellisense list for the class, which is just as sparse.

There seems no way to set the icon.

However, if you do the following, you can set it by hand:

1. Add "using System.Globalization;" to your code.

2. At the start of your constructor, add:

System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(<yourClassName>));

where <yourClassName> is the name of your class.

3. After "InitializeComponent();" add:

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

Never mind that Intellisense doesn't recognize "Icon" as a valid
property. In this case (for some reason) Intellisense isn't very
intelligent.

4. Create a normal, vanilla Form in your project. Set the icon in that
form. Now open the form's .resx file in Visual Studio. Switch to .XML
mode. At the bottom of the file you will see a <data> tag with the
name "$this.Icon". Copy this entire tag (down to and including
</data>) onto the clipboard.

5. Open the .resx file for your print preview dialog in Visual Studio.
Switch to XML mode. Paste the <data> tag and all of its contents to
the end of the file, just before the </root> closing tag.

6. Delete the vanilla form that you added to your project.

This will set the icon for your print preview dialog.

Does anyone have any idea why PrintPreviewDialog would act like this?

Does anyone know why, in the .NET documentation, PrintPreviewDialog is
listed as having no Icon property under "list all members", even
though its parent class, "System.Windows.Forms.Form", according to the
same documentation, has a public Icon property? (And in .NET it's
impossible to obscure properties of parent classes.)

To add to the mystery, there is documentation for a
PrintPreviewDialog.Icon property (oddly inaccessible from the
documentation for PrintPreviewDialog), that claims that "This member
supports the .NET Framework infrastructure and is not intended to be
used directly from your code." You can see it here:

http://msdn.microsoft.com/library/d...dowsFormsPrintPreviewDialogClassIconTopic.asp

Curiouser and curiouser.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top