Need some help with using PageSetupSettings-dialog

M

Mika M

Hi!

I have some problems with setting PrintDocument margins using
PageSetupDialog. Here some code to explain my problem...

First PrintDocument declaring this way...

Private pd As PrintDocument = New PrintDocument


It is possible to set default values for PrintDocument printing in
App.Config-file, and it contains following lines...

<add key="Printing.TopMargin" value="2" />
<add key="Printing.LeftMargin" value="7" />
<add key="Printing.BottomMargin" value="0" />
<add key="Printing.RightMargin" value="0" />


Application retrieves default values for PrintDocument when application
is started this way...

Private Sub frmLabels_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'// Get default settings for PrintDocument
With pd.DefaultPageSettings
.Margins.Top =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.TopMargin")) * 10
.Margins.Bottom =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.BottomMargin"))
* 10
.Margins.Right =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.RightMargin"))
* 10
.Margins.Left =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.LeftMargin")) * 10
'...
End With
End Sub


Here is how application uses PageSetupDialog to setup PrintDocument
settings...

Private Sub mnuPageSetup_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPageSetup.Click
Try
Cursor = Cursors.WaitCursor
Dim dlg As PageSetupDialog = New PageSetupDialog

dlg.Document = pd
dlg.PrinterSettings = pd.PrinterSettings
Cursor = Cursors.Default

If (dlg.ShowDialog() = DialogResult.OK) Then
pd.PrinterSettings = dlg.PrinterSettings
End If

dlg.Dispose()

Catch ex As Exception
MessageBox.Show(ex.Message, "Error (mnuPageSetup_Click)",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub


My problem is when user is clicking mnuPageSetup_Click first time
Margin-settings retrieved from App.Config are fine when PageSetupDialog
opens, but if user press OK-button and then turns back, Margin-settings
are not same any more after turning back, after this Margins
(millimeters)-frames orginal Left=7 will be 2,8 and original Top=2 will
be 0,8 in this case - why?

Ofcourse this was not happening if user pressed Cancel-button. Propably
I'm doing something wrong, but what? Anyway I'm getting printings fine.

By a way... 1cm = 0,3937" and 1" = 2,540005cm ...if needed :)
 
M

Mika M

Well... I notices example code from
http://www.startvbdotnet.com/controls/printdialog1.aspx

....and changed mnuPageSetup_Click a little bit (see below between
previous message code lines), but it didn't solve my problem :(
Hi!

I have some problems with setting PrintDocument margins using
PageSetupDialog. Here some code to explain my problem...

First PrintDocument declaring this way...

Private pd As PrintDocument = New PrintDocument


It is possible to set default values for PrintDocument printing in
App.Config-file, and it contains following lines...

<add key="Printing.TopMargin" value="2" />
<add key="Printing.LeftMargin" value="7" />
<add key="Printing.BottomMargin" value="0" />
<add key="Printing.RightMargin" value="0" />


Application retrieves default values for PrintDocument when application
is started this way...

Private Sub frmLabels_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'// Get default settings for PrintDocument
With pd.DefaultPageSettings
.Margins.Top =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.TopMargin")) * 10
.Margins.Bottom =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.BottomMargin"))
* 10
.Margins.Right =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.RightMargin"))
* 10
.Margins.Left =
Integer.Parse(ConfigurationSettings.AppSettings("Printing.LeftMargin"))
* 10
'...
End With
End Sub


Here is how application uses PageSetupDialog to setup PrintDocument
settings...

Private Sub mnuPageSetup_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPageSetup.Click
Try
Cursor = Cursors.WaitCursor
Dim dlg As PageSetupDialog = New PageSetupDialog

dlg.Document = pd
dlg.PageSettings = pd.DefaultPageSettings
Cursor = Cursors.Default

If (dlg.ShowDialog() = DialogResult.OK) Then
pd.DefaultPageSettings = dlg.PageSettings
End If

dlg.Dispose()

Catch ex As Exception
MessageBox.Show(ex.Message, "Error (mnuPageSetup_Click)",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
 

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