471,579 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Need some help with using PageSetupSettings-dialog

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("P rinting.TopMargin")) * 10
.Margins.Bottom =
Integer.Parse(ConfigurationSettings.AppSettings("P rinting.BottomMargin"))
* 10
.Margins.Right =
Integer.Parse(ConfigurationSettings.AppSettings("P rinting.RightMargin"))
* 10
.Margins.Left =
Integer.Parse(ConfigurationSettings.AppSettings("P rinting.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 :)

--
Thanks in advance!

Mika
Nov 21 '05 #1
1 1321
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("P rinting.TopMargin")) * 10
.Margins.Bottom =
Integer.Parse(ConfigurationSettings.AppSettings("P rinting.BottomMargin"))
* 10
.Margins.Right =
Integer.Parse(ConfigurationSettings.AppSettings("P rinting.RightMargin"))
* 10
.Margins.Left =
Integer.Parse(ConfigurationSettings.AppSettings("P rinting.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


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 :)

--
Thanks in advance!

Mika

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by mike | last post: by
48 posts views Thread by Chad Z. Hower aka Kudzu | last post: by
7 posts views Thread by Tee | last post: by
8 posts views Thread by skumar434 | last post: by
reply views Thread by U S Contractors Offering Service A Non-profit | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.