Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > BOOK: Visual Basic 2005 Programmer's Reference
|
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2007, 01:57 PM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't get image to fit in print preview margin.

I am trying to use the FitPictureToMargins(p.650 Visual Basic Programmer's Reference) sub, but it doesn't quite work for me.

I have a form that contains a PrintPreviewControl on it.

In my Form_Load event I assign a module level PrintDocument object to a PrintPreviewControl's document property.

I then have a sub that loads a module level Image variable with a bitmap file saved on disk, and then calls the PrintPreviewControl's InvalidatePreview method.

In the PrintDocument_PrintPage event I first draw a rectangle to e.Marginbounds (so I can see the margins for testing), then I call the FitPictureToMargins sub. Finally I draw the module level image object using the e.Graphics.DrawImage method.

The problem is that although the image is rescaled when drawn to the graphics, it doesn't quite fit in the margins. I believe this has something to do with the units used in the rectangles. The bitmap is using pixels I assume, and according to the help, e.MarginBounds uses 1/100 inch. I have tried converting the width and height of the image to inches (using the e.graphics.dpiX and .dpiY) before passing to the FitPictureToMargins with no luck. I have also tried changing the e.Graphics.PageUnit to inch and then converting all units passed to the FitPictureToMargins to inches with no luck as well. I am pretty stumped.

Maybe I am missing something obvious here? I am pretty new to GDI+ so feel free to ask the obvious questions.

Avery
 
Old April 28th, 2007, 08:42 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi Avery,

If you email me (RodStephens@vb-helper.com) your zipped project I'll take a look.

Rod


Rod
RodStephens@vb-helper.com

Check out my latest book:
"Expert One-on-One Visual Basic 2005 Design and Development"
http://www.vb-helper.com/one_on_one.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
 
Old May 1st, 2007, 08:56 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

I figured this out. Your call to DrawImage looks like this:

    g.DrawImage(_testImage, 0, 0)

Here you have not included the image's width or height. When you do that, it draws the image using its "physical size" so it's the same size whether you're drawing on the screen, a printer, or something else. At least in theory. In this case, however, the program has fiddled with the Graphics object's transformation so it doesn't work out so well.

Try this:

    g.DrawImage(_testImage, 0, 0, _testImage.Width, _testImage.Height)

Now the code indicates explicitly what size to give the image so it doesn't try to get smart. The program's transformation scales it nicely so it fits where you'd expect.

Rod
RodStephens@vb-helper.com

Check out my latest book:
"Expert One-on-One Visual Basic 2005 Design and Development"
http://www.vb-helper.com/one_on_one.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
 
Old May 1st, 2007, 11:01 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That solved it Ron!

Thanks for the help.

Avery





Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox problem print preview vs. print jenisageek Access 5 May 2nd, 2008 12:54 PM
Printing fit to page print arnabghosh Javascript How-To 2 July 29th, 2007 05:58 PM
Print preview scandalous Access 4 February 23rd, 2007 10:45 AM
help in print preview star20010us General .NET 0 September 8th, 2006 07:06 PM
Print and print preview file on the website withou appleLover General .NET 0 February 19th, 2005 02:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.