HighTechTalks DotNet Forums  

GetHardMargins Actual Height Paper

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss GetHardMargins Actual Height Paper in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
JZ
 
Posts: n/a

Default GetHardMargins Actual Height Paper - 09-27-2004 , 05:20 AM






Hi,

I've found the GetHardMargins code written by Ron Allen.
I have it working...

But I've not exactly sure what to do with it.

I simple want to paint a drawing over 2 pages.
The 2 bits of paper would then be trimmed and stuck together with tape.

I think the easiest thing for me to do is do derive a number which will all
me to pass in an offset into my drawing function.

Any suggestions how I can do this?

--
JZ

Heres the code I've got...
Dim lLeft As Single

Dim lTop As Single

Dim lRight As Single

Dim lBottom As Single

Dim hdcPtr As IntPtr

Dim gr As Graphics =
PrintDocument1.PrinterSettings.CreateMeasurementGr aphics()

hdcPtr = gr.GetHdc

GetHardMargins(hdcPtr, lLeft, lTop, lRight, lBottom)

gr.ReleaseHdc(hdcPtr)

Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As IntPtr,
ByVal nIndex As Int32) As Int32

Private Sub GetHardMargins(ByVal hDC As IntPtr, ByRef Left As Single, ByRef
Top As Single, ByRef Right As Single, ByRef Bottom As Single)



Const PHYSICALOFFSETX As Int32 = 112

Const PHYSICALOFFSETY As Int32 = 113

Const HORZRES As Int32 = 8

Const VERTRES As Int32 = 10

Const HORZSIZE As Int32 = 4

Const VERTSIZE As Int32 = 6

Dim offx As Single = Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETX))

Dim offy As Single = Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETY))

Dim resx As Single = Convert.ToSingle(GetDeviceCaps(hDC, HORZRES))

Dim resy As Single = Convert.ToSingle(GetDeviceCaps(hDC, VERTRES))

Dim hsz As Single = Convert.ToSingle(GetDeviceCaps(hDC, HORZSIZE)) / 25.4F '
Screen width in inches.

Dim vsz As Single = Convert.ToSingle(GetDeviceCaps(hDC, VERTSIZE)) / 25.4F '
Screen height in inches.

Dim ppix As Single = resx / hsz

Dim ppiy As Single = resy / vsz

Left = (offx / ppix) * 100.0F

Top = (offy / ppix) * 100.0F

Bottom = Top + (vsz * 100.0F)

Right = Left + (hsz * 100.0F)

End Sub



Reply With Quote
  #2  
Old   
Ron Allen
 
Posts: n/a

Default Re: GetHardMargins Actual Height Paper - 09-27-2004 , 09:09 AM






JZ,
GetHardMargins is just used to return the hard printer margins so you
can correctly offset your drawing area. You can get the vertical drawing
height by subtracting the top margin from the bottom one and get the width
in the same way.
Now you will have to organize your drawing to do only parts or just draw
the whole drawing on the first page after translating -left, -top to get
offsets correct and then on the second page do a translate
by -left, -(bottom - top) and then draw the whole thing again. This should
get the two parts shown correctly as the items outside the page boundaries
will be ignored.

Ron Allen
"JZ" <jj (AT) anon (DOT) anon.com> wrote

Quote:
Hi,

I've found the GetHardMargins code written by Ron Allen.
I have it working...

But I've not exactly sure what to do with it.

I simple want to paint a drawing over 2 pages.
The 2 bits of paper would then be trimmed and stuck together with tape.

I think the easiest thing for me to do is do derive a number which will
all
me to pass in an offset into my drawing function.

Any suggestions how I can do this?

--
JZ

Heres the code I've got...
Dim lLeft As Single

Dim lTop As Single

Dim lRight As Single

Dim lBottom As Single

Dim hdcPtr As IntPtr

Dim gr As Graphics =
PrintDocument1.PrinterSettings.CreateMeasurementGr aphics()

hdcPtr = gr.GetHdc

GetHardMargins(hdcPtr, lLeft, lTop, lRight, lBottom)

gr.ReleaseHdc(hdcPtr)

Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As
IntPtr,
ByVal nIndex As Int32) As Int32

Private Sub GetHardMargins(ByVal hDC As IntPtr, ByRef Left As Single,
ByRef
Top As Single, ByRef Right As Single, ByRef Bottom As Single)



Const PHYSICALOFFSETX As Int32 = 112

Const PHYSICALOFFSETY As Int32 = 113

Const HORZRES As Int32 = 8

Const VERTRES As Int32 = 10

Const HORZSIZE As Int32 = 4

Const VERTSIZE As Int32 = 6

Dim offx As Single = Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETX))

Dim offy As Single = Convert.ToSingle(GetDeviceCaps(hDC, PHYSICALOFFSETY))

Dim resx As Single = Convert.ToSingle(GetDeviceCaps(hDC, HORZRES))

Dim resy As Single = Convert.ToSingle(GetDeviceCaps(hDC, VERTRES))

Dim hsz As Single = Convert.ToSingle(GetDeviceCaps(hDC, HORZSIZE)) / 25.4F
'
Screen width in inches.

Dim vsz As Single = Convert.ToSingle(GetDeviceCaps(hDC, VERTSIZE)) / 25.4F
'
Screen height in inches.

Dim ppix As Single = resx / hsz

Dim ppiy As Single = resy / vsz

Left = (offx / ppix) * 100.0F

Top = (offy / ppix) * 100.0F

Bottom = Top + (vsz * 100.0F)

Right = Left + (hsz * 100.0F)

End Sub





Reply With Quote
  #3  
Old   
JZ
 
Posts: n/a

Default Re: GetHardMargins Actual Height Paper - 09-27-2004 , 09:38 AM



Hi,

Thanks for your reply.

What are the values that I need to look at in relation to the print document
or print preview?

I just call printdocument.print from print preview.

I'm not too bothered if the print preview doesn't look quite right, as long
as it prints ok.

I currently pass in an offset for the second page, so the drawing starts
half way across.
So I just need to subtract a little from that.

--
JZ



Reply With Quote
  #4  
Old   
JZ
 
Posts: n/a

Default Re: GetHardMargins Actual Height Paper - 09-27-2004 , 10:02 AM



Hi,

I guess what I really need to know is how to convert the hard left margin
value into something I subtract from the default drawing number format.

?

--
JZ



Reply With Quote
  #5  
Old   
Ron Allen
 
Posts: n/a

Default Re: GetHardMargins Actual Height Paper - 09-27-2004 , 01:14 PM



JZ,
To compensate for margins you can call
e.Graphics.TranslateTransform(-left, -top) where left and top are the values
returned for the hard left and top margins respectively and e is the
PrintPageEventArgs parameter for PrintPage.
Calling GetHardMargins at the beginning of printing or for each
PrintPage should return 0 for a print preview and the actual values in
1/100ths of an inch when going out to the printer.

Ron Allen
"JZ" <jj (AT) anon (DOT) anon.com> wrote

Quote:
Hi,

I guess what I really need to know is how to convert the hard left margin
value into something I subtract from the default drawing number format.

?

--
JZ





Reply With Quote
  #6  
Old   
JZ
 
Posts: n/a

Default Re: GetHardMargins Actual Height Paper - 09-28-2004 , 08:23 AM



Hi,

Thanks...

Yes I do tranform already.

I'm sorry to over complicate things.
I presumed that I'd have the convert the values some how.
I wasn't expecting everything to be done for me.

Thanks.

--
JZ



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.