BUG: Printing Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Programatix

    #1

    BUG: Printing Problem

    Hi,

    I am working on the PrintDocument, PrintDialog, PageSetupDialog and
    PrintPreviewCon trol 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.PageSe ttings
    Dim pagesetupdialog As System.Windows. Forms.PageSetup Dialog

    pagesettings = New System.Drawing. Printing.PageSe ttings
    With pagesettings.Ma rgins
    .Left = 100
    .Right = 100
    .Top = 100
    .Bottom = 100
    End With

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

    ' Values printed out are not the same as entered
    With pagesettings.Ma rgins
    Console.WriteLi ne(.Left)
    Console.WriteLi ne(.Right)
    Console.WriteLi ne(.Top)
    Console.WriteLi ne(.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.PageSe ttings
    Dim pagesetupdialog As System.Windows. Forms.PageSetup Dialog

    pagesettings = New System.Drawing. Printing.PageSe ttings
    With pagesettings.Ma rgins
    .Left = 100
    .Right = 100
    .Top = 100
    .Bottom = 100
    End With

    pagesetupdialog = New System.Windows. Forms.PageSetup Dialog
    With pagesetupdialog
    .PageSettings = pagesettings

    ' Keep the original setting
    Dim marginSaved As System.Drawing. Printing.Margin s
    marginSaved = pagesettings.Ma rgins

    ' Convert to milimeters
    pagesettings.Ma rgins =
    System.Drawing. Printing.Printe rUnitConvert.Co nvert(pagesetti ngs.Margins,
    System.Drawing. Printing.Printe rUnit.Display,
    System.Drawing. Printing.Printe rUnit.TenthsOfA Millimeter)

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

    With pagesettings.Ma rgins
    Console.WriteLi ne(.Left)
    Console.WriteLi ne(.Right)
    Console.WriteLi ne(.Top)
    Console.WriteLi ne(.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 PrintPreviewCon trol.
    Setting the value to True does not effect the preview shown by
    PrintPreviewCon trol 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.Page Unit = GraphicsUnit.Mi llimeter

    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.



Working...