473,738 Members | 11,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing using margins

tm
I am trying to print a form using the following code, everything works fine
but the margins are not acted upon. What I am I doing wrong?

Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphi cs()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0, s)
End Sub

Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles
printDocument1. PrintPage

Dim margins As New Margins(0, 0, 600, 0)
printDocument1. DefaultPageSett ings.Margins = margins
e.Graphics.Draw Image(memoryIma ge, 0, 0)

End Sub

Feb 3 '06 #1
7 2752
tm,
You didn't say which version of the framework you are using. For 1.x
you will need to compensate for the 'hard margins' on the printer by
PInvoking GetDeviceCaps to get the margins. Also you won't be able to print
except for inside those margins as the printer isn't capable of printing
there. Except for some very high end printers most aren't capable of
printing to the edge of the paper.
You can look for GetHardMargins in this newsgroup or in
microsoft.publi c.dotnet.framew ork.drawing to find some code to get the
actual printer margin values. If you are using FW 2.0 you can use the
properties of the PrintDocument to find the margins.

Ron Allen
"tm" <tb***@cwnet.co m> wrote in message
news:%2******** *******@TK2MSFT NGP14.phx.gbl.. .
I am trying to print a form using the following code, everything works fine
but the margins are not acted upon. What I am I doing wrong?

Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphi cs()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0,
s)
End Sub

Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles
printDocument1. PrintPage

Dim margins As New Margins(0, 0, 600, 0)
printDocument1. DefaultPageSett ings.Margins = margins
e.Graphics.Draw Image(memoryIma ge, 0, 0)

End Sub

Feb 4 '06 #2
tm
Ron,

I am using Framework 2.0

I have tried searching "GetHardMar gins " with no luck.
If I add the following to my sub printDocument1_ PrintPage
I do see my margins settings, but this just proves that I can
set and read back the PageSetupDialog 1 information. It
seems that the info is not getting back to the printer.
What ties the PageSetupDialog to the system default printer?

With PageSetupDialog 1

Dim leftMargin As Single = .PageSettings.M argins.Left

Dim rightMargin As Single = .PageSettings.M argins.Right

Dim topMargin As Single = .PageSettings.M argins.Top

Dim BottomMargin As Single = .PageSettings.M argins.Bottom

End With

tom
Feb 5 '06 #3
You can get the printable page size from the PrintPageEventA rgs.PageBounds
which is passed to the PrintPage Event.
--
Dennis in Houston
"tm" wrote:
Ron,

I am using Framework 2.0

I have tried searching "GetHardMar gins " with no luck.
If I add the following to my sub printDocument1_ PrintPage
I do see my margins settings, but this just proves that I can
set and read back the PageSetupDialog 1 information. It
seems that the info is not getting back to the printer.
What ties the PageSetupDialog to the system default printer?

With PageSetupDialog 1

Dim leftMargin As Single = .PageSettings.M argins.Left

Dim rightMargin As Single = .PageSettings.M argins.Right

Dim topMargin As Single = .PageSettings.M argins.Top

Dim BottomMargin As Single = .PageSettings.M argins.Bottom

End With

tom

Feb 5 '06 #4
tm
Dennis,

I capture the image in the CaptureScreen sub.

What I want to do is use Margins to begin printing
6 inches down from the top. But the default printer
seems not to see the new margins I set in the
printDocument1 event and continus to print
at the top.

If you have any suggestions of what I am doing
wrong I would appreciate your feed back.

tom
Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphi cs()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0, s)
End Sub
Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
printDocument1. PrintPage

Dim margins As New Margins(0, 0, 600, 0)
printDocument1. DefaultPageSett ings.Margins = margins
e.Graphics.Draw Image(memoryIma ge, 0, 0)

End Sub
Feb 5 '06 #5
You are drawing to the page graphics object and you need to use the point for
the drawing to start. If you want the drawing to be 6 inches from the top of
the paper and 2 inches from the left side of the paper, use

e.Graphics.Draw Image(memoryIma ge, 200, 600).

The margins have nothing to do with it.
--
Dennis in Houston
"tm" wrote:
Dennis,

I capture the image in the CaptureScreen sub.

What I want to do is use Margins to begin printing
6 inches down from the top. But the default printer
seems not to see the new margins I set in the
printDocument1 event and continus to print
at the top.

If you have any suggestions of what I am doing
wrong I would appreciate your feed back.

tom
Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphi cs()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0, s)
End Sub
Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
printDocument1. PrintPage

Dim margins As New Margins(0, 0, 600, 0)
printDocument1. DefaultPageSett ings.Margins = margins
e.Graphics.Draw Image(memoryIma ge, 0, 0)

End Sub

Feb 5 '06 #6
tm
Thanks Dennis, I have been working on this for a week.

Now that I can print at the bottom I have another question,
is it possible to do two CaptureScreen() and send one two
print at the top and the other to print at the bottom.

Or prevent the form feed from ejecting the paper which would
allow printing on top then print at bottom then eject the paper.

tom

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:50******** *************** ***********@mic rosoft.com...
You are drawing to the page graphics object and you need to use the point
for
the drawing to start. If you want the drawing to be 6 inches from the top
of
the paper and 2 inches from the left side of the paper, use

e.Graphics.Draw Image(memoryIma ge, 200, 600).

The margins have nothing to do with it.
--
Dennis in Houston
"tm" wrote:
Dennis,

I capture the image in the CaptureScreen sub.

What I want to do is use Margins to begin printing
6 inches down from the top. But the default printer
seems not to see the new margins I set in the
printDocument1 event and continus to print
at the top.

If you have any suggestions of what I am doing
wrong I would appreciate your feed back.

tom
Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphi cs()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0,
s)
End Sub
Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
printDocument1. PrintPage

Dim margins As New Margins(0, 0, 600, 0)
printDocument1. DefaultPageSett ings.Margins = margins
e.Graphics.Draw Image(memoryIma ge, 0, 0)

End Sub

Feb 6 '06 #7
You can print as many images as you want wherever you want, even overlapping
so long as you do it before exiting the routine. If you want to change
pages, just set the PrintPageEventA rgs.HasMorePage s = True and the PrintPages
sub will be called again. You can use a static variable in the sub to keep
track of which page you are on.

Dennis in Houston
"tm" wrote:
Thanks Dennis, I have been working on this for a week.

Now that I can print at the bottom I have another question,
is it possible to do two CaptureScreen() and send one two
print at the top and the other to print at the bottom.

Or prevent the form feed from ejecting the paper which would
allow printing on top then print at bottom then eject the paper.

tom

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:50******** *************** ***********@mic rosoft.com...
You are drawing to the page graphics object and you need to use the point
for
the drawing to start. If you want the drawing to be 6 inches from the top
of
the paper and 2 inches from the left side of the paper, use

e.Graphics.Draw Image(memoryIma ge, 200, 600).

The margins have nothing to do with it.
--
Dennis in Houston
"tm" wrote:
Dennis,

I capture the image in the CaptureScreen sub.

What I want to do is use Margins to begin printing
6 inches down from the top. But the default printer
seems not to see the new margins I set in the
printDocument1 event and continus to print
at the top.

If you have any suggestions of what I am doing
wrong I would appreciate your feed back.

tom
Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphi cs()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromIm age(memoryImage )
memoryGraphics. CopyFromScreen( Me.Location.X, Me.Location.Y, 0, 0,
s)
End Sub
Private Sub printDocument1_ PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing. Printing.PrintP ageEventArgs) Handles _
printDocument1. PrintPage

Dim margins As New Margins(0, 0, 600, 0)
printDocument1. DefaultPageSett ings.Margins = margins
e.Graphics.Draw Image(memoryIma ge, 0, 0)

End Sub


Feb 7 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4855
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been selected. For example, if I were to have 5 pages with every second page printing, I would get the following results: Page 1 = Print OK Page 2 = Blank Page 3 = Print OK Page 4 = Blank
0
2299
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl 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".
0
2127
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl 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".
0
1498
by: JF Turcotte | last post by:
Hi I'm unsuccessfully trying to print a form's image under VB.NET. To print under .NET is a real pain in the , I find it to be complex, lenghty, confusing, upsetting and ultimately not to be working at all. My strategy is first to save the form's image as a bitmap (this works, I can save the image to a file). Then I use the printer's Graphics object's drawImage method to send it
2
3467
by: qumpus | last post by:
My program right now generates USPS style shipping label using System.Drawing.Graphics. It works fine except that the printer prints really slowly. I want to make my program take advantage of true type fonts. So I assume it's possible to send Font Type and the text to the printer, and the printer should digest and print faster. Still, barcode info needs to be sent as an image. When I print fifty copies of the same label it prints really...
8
9626
by: Tinus | last post by:
Hello all, Because you have been so helpfull the last couple of times, I thought after testing and wasting more than 20 pages (and google-ling for 3 days :-( ). I would ask you again for your help. The problem is this: If I print a rectangle which begins at (0,0) and the margins are also set to 0 (l:0, t:0, r:0, b:0) then it prints fine (ok, not quite because 0,0 is inside the none printable area but I corrected for that by checking...
4
14079
by: iwdu15 | last post by:
can anybody help me print from a rich text box? i tried the way they showed on the MSDN web page, but it did not work. I am using VB.net 2003...any help would be appreciated
7
2484
by: DazedAndConfused | last post by:
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the left and right where there is no print. The document displays perfect in print preview, but when I print it, about 1/2 inch on the right is not printed (leaving about 3/4 inch empty margin on the right side of the page). The left side starts about 1/4 inch in and prints just like I expect it to. I tried setting the margins to 0 and OriginAtMargins = True. The print...
8
9017
by: Frank Rizzo | last post by:
I am trying to print huge images (much bigger than target paper). I try and use e.PageSettings.HardMarginX and e.PageSettings.HardMarginY in the PrintDocument's PrintPage event to try and determine the maximum area that I can print on. However, the edge of the image invariably gets cut off, as if the HardMargin info is wrong. I posted the code below as I can't understand what I am doing wrong. Is information in e.PageSettings reliable?...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.