Setting printer margins by code

I know I can set printer margins through PrinterSetup.PageSetupDialog.
But is it possible to fix them by code (if necessary using some declare)?
I’ve not been able to find any.

You can modify the setup string and reaffect it to the openPrinterDialog.

UX Note: You can fudge your own margins in more, but you shouldn’t override what the user has told you their margins are and print outside that.

Thanks Michel and Tim for your answers.

In fact my interest is forced by the situation, not because I like to know it.
I have an application that is quite old (about 30 years now). It has survived several languages but since 2006 is Xojo (Real Basic, Real Software and Xojo). This application draws a full page with a graphic of a structure (picture). Up to now it didn’t matter which the margin was, I could fill the whole page with my picture. But now with the new graphic system, if I don’t fix margin = 0 I can not fill the whole page as before.

I tried to modify the SetupString but I had no success.
Before PageSetupDialog, SetupString has no reference to margins. Only when the dialog-window has been opened and OK button has been pressed, then SetupString is much longer and has many references to margins.
What should I do? Add margin references to the SetupString although there are none in it?

Thanks for your help.

I know of no way to set the margins in advance in the print setup dialog.

Finally I got a way to set margins to zero. At least it works in my case.

[code]Sub SetMarginsZero()

#If TargetWindows Then

Dim Codes() As String = gPageSetup.SetupString.Split(EndOfLine.Windows)

For i As Integer = 0 To Codes.Ubound
If Codes(i).InStr(“MarginLeft”) <> 0 Then Codes(i) = “MarginLeft=0”
If Codes(i).InStr(“MarginRight”) <> 0 Then Codes(i) = “MarginRight=0”
If Codes(i).InStr(“MarginTop”) <> 0 Then Codes(i) = “MarginTop=0”
If Codes(i).InStr(“MarginBottom”) <> 0 Then Codes(i) = “MarginBottom=0”

gPageSetup.SetupString = Join(Codes, EndOfLine.Windows)


End Sub[/code]

I publish it here just in case it can serve someone else or if you have a better idea.
At this moment I’ve only tried it on Windows. But as it is just Xojo, maybe it works on different platforms as well.

So Ramon, you pass this setupstring to the pagesetup before calling pagesetupdialog, and margins show up as zero ?

OK. So I looked closer, in fact you simply modify the values after the printSetup has been created by printerSetupDialog. It is no different from what I suggested above.

I tend to agree with Tim, though. The user should be able to setup his margins himself and not mess with his choices.

One clean way to change margins at the launch of the printerSetupDialog is to use sendkeys or pressKeyMBS to set one field, then tab, then another field, and so on.

That way the user is presented with the dialog and all margins set to zero, but if he wants different margins, that will not be changed on him.

Yes Michel, you are right.
I also don’t like modifying what users have already selected.
This approach is only temporary until I can set a SetupString without using PageSetupDialog.
I know I can save SetupString and recover it later. In fact I think you worked with it in another thread.
But there were some problems with encodings and I have not resolved them yet.

Then look into setting the margins in the setup dialog itself.