473,509 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BUG: Printing

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.
Nov 20 '05 #1
0 1157

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

Similar topics

0
2273
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...
0
2108
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...
34
1847
by: Marcel van Kervinck | last post by:
Dear all, I would like to confirm my suspicion of a compiler bug in gcc4 for MacOSX. The code example below expects that the initializer of 'v' sets all elements in v.u.bytes to zero, as...
3
2648
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
2216
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
5377
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,...
9
1659
by: Summercoolness | last post by:
it seems that the behavior of "print" is that it will round off properly for any floating point imperfection, such as shown in the first two samples. The third sample seems to be a bug? It...
4
1795
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
2265
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...
3
1355
by: William Chang | last post by:
Is the different behavior between __repr__ and __str__ intentional when it comes to printing lists? Basically I want to print out a list with elements of my own class, but when I overwrite __str__,...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.