473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

BUG: Printing Problem

Hi,

I am working on the PrintDocument, PrintDialog, PageSetupDialog and
PrintPreviewControl components of Visual Studio .NET 2003. My developement
machine is running Windows XP.

There are some problems I encountered while using them. Please note that,
the Regional and Language setting on my machine is using "Metric"
measurement system (where the default is "US"). In this case, the
measurement unit is "milimeters" and not "inches".
PROBLEM #1
``````````````
The first problem is with PageSetupDialog. The following code,

Dim pagesettings As System.Drawing.Printing.PageSettings
Dim pagesetupdialog As System.Windows.Forms.PageSetupDialog

pagesettings = New System.Drawing.Printing.PageSettings
With pagesettings.Margins
.Left = 100
.Right = 100
.Top = 100
.Bottom = 100
End With

pagesetupdialog = New System.Windows.Forms.PageSetupDialog
With pagesetupdialog
.PageSettings = pagesettings
.ShowDialog()
End With

' Values printed out are not the same as entered
With pagesettings.Margins
Console.WriteLine(.Left)
Console.WriteLine(.Right)
Console.WriteLine(.Top)
Console.WriteLine(.Bottom)
End With

will reproduce the problem I'm facing.

Before calling the ShowDialog() method of the PageSetupDialog component, I
have already set the Margins to 100. Although my OS's measurement system is
set to "Metric", Visual Studio .NET still uses inches (0.01 in) for it's
measurement unit. In my case, the Margins are set to 1 inch.

On calling the ShowDialog() method, what you see is the margins are all set
to 10 (and the unit is milimeters). On clicking the OK button, the
PageSetupDialog component will convert the value entered in it's dialog to
inches (0.01 in). As the result, the margins after the ShowDialog() is
called are changed to 39 (100/2.54=39.xxxxxx).

This surely is a BUG (or am I missing something here).

I have a solution for this problem and the code is as below.

Dim pagesettings As System.Drawing.Printing.PageSettings
Dim pagesetupdialog As System.Windows.Forms.PageSetupDialog

pagesettings = New System.Drawing.Printing.PageSettings
With pagesettings.Margins
.Left = 100
.Right = 100
.Top = 100
.Bottom = 100
End With

pagesetupdialog = New System.Windows.Forms.PageSetupDialog
With pagesetupdialog
.PageSettings = pagesettings

' Keep the original setting
Dim marginSaved As System.Drawing.Printing.Margins
marginSaved = pagesettings.Margins

' Convert to milimeters
pagesettings.Margins =
System.Drawing.Printing.PrinterUnitConvert.Convert (pagesettings.Margins,
System.Drawing.Printing.PrinterUnit.Display,
System.Drawing.Printing.PrinterUnit.TenthsOfAMilli meter)

' Show the page setup dialog
If .ShowDialog() = DialogResult.Cancel Then
' If user clicked Cancel, restore the saved margin
pagesettings.Margins = marginSaved
End If
End With

With pagesettings.Margins
Console.WriteLine(.Left)
Console.WriteLine(.Right)
Console.WriteLine(.Top)
Console.WriteLine(.Bottom)
End With

But there is a problem with it. The conversion between milimeters and inches
causes the measurement to be inaccurate.
PROBLEM #2
``````````
The OriginAtMargins property of the PrintDocument component does not work
properly when the PrintDocument is added into the PrintPreviewControl.
Setting the value to True does not effect the preview shown by
PrintPreviewControl but the printed result is correct.
PROBLEM #3
``````````
When handling the PrintPage event of the PrintDocument, if the
OriginAtMargins of the PrintDocument is set to True and I set,

e.Graphics.PageUnit = GraphicsUnit.Millimeter

then the top margin is measured as milimeters while the left margin is
measured as inches.
The problem discuss above might not be bugs but I have checked the MSDN
library but it does not seem to help much. Any help is really appreciated.

Thanks in advance.

Jul 21 '05 #1
0 2085

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Edward K. Ream | last post by:
Hi, I am trying to run the following docstring using docutils.DocTestSuite: """ >>> s = "a\n \t\n\t\t \t\nb" etc... """ However, docutils complains about "inconsistent leading...
0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
3
by: Jochen Kalmbach | last post by:
Hello, if an PrinterSettings-Instance is not set-up correctly (for example just by using the default-constructor), then the "ToString()"_method will throw an exception! Unhandled...
2
by: Martin | last post by:
I have encountered a bug in print preview: In my program, data for printing is taken from arrays. When print preview is invoked or page is printed directly, it is ok, but when user prints from...
4
by: Steph. | last post by:
Hi, Is there a BUG in the printdialog ? When I create a PrintDialog ans set the "DefaultPageSettings.Landscape" property to "false" and then display the dialog, select "Landscape" and click OK,...
0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
2
by: Amjad | last post by:
I use the PageSetupDialog box to allow the user to change the page margins before printing. The problem is when I open the dialog box and type in margin values in millimeters (as it says in the...
4
by: Number 11950 - GPEMC! Replace number with 11950 | last post by:
When www.geoceanis.com is sent to the print preview or alternatively the printer, the second page is displayed or printed by IE, but lost to Gecko (Netscape, Firefox, Moxilla, etc...). NOTE: Both...
38
by: Mark Dickinson | last post by:
I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC, in case it's relevant.) (0.0, 0.0) (-0.0, -0.0) I would have expected y to be -0.0 in the first case, and 0.0 in the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.