Printing GDI+ from VB.NET 2003 or before is okay with me

This may be a tough one. I have searched the web and this site but found nothing that clearly explains or demonstrates printing GDI+ from vb.net.

Here is some code from the prototype I am developing:

Imports System.Data
Imports Oracle.DataAccess.Client
Imports System.Drawing.Drawing2D
Imports System.Drawing.Graphics

Controls on the form:
tab control with tab named tbpstublayout

Controls on the tab:
text boxes - txtPlyWidth, txtPlyLength, txtRowLocationX, txtRowLocationY
combobox - cboHoleSize (this could also be a textbox)
button - btnRowLocation

      Private Sub tbpStubLayout_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
       Handles tbpStubLayout.Paint
            ' The drawing area is 420 x 420 pixels
            ' Longest dimension is 420 pixels
            ' MaxPixelsPerInch: 420/(longest dimension)- Determine pixels/inch for the longest dimension
            ' (Shortest dimension) * MaxPixelsPerInch - the number of pixels in the shortest dimension

            Dim ppi As Integer
            Dim LongDim As Double
            Dim HoleSize As Integer

            Dim g As Graphics = e.Graphics
            Dim gp As GraphicsPath = New GraphicsPath
            'Dim pn As Pen
            'Dim rect As Rectangle
            Dim yinc As Integer = 66
            Dim RowLocY As Integer
            Dim RowLocX As Integer
            ' Create a GraphicsPath object and add a rectangle to it.
            Dim pathRect As New Rectangle(400, 50, 0, 0)

            Try
                  If txtPlyLength.Text - txtPlyWidth.Text >= 0 Then
                        ppi = 420 / txtPlyLength.Text
                  Else
                        ppi = 420 / txtPlyWidth.Text
                  End If
                  pathRect.Width = CInt(txtPlyWidth.Text * ppi)
                  pathRect.Height = CInt(txtPlyLength.Text * ppi)
                  HoleSize = CInt(cboHoleSize.Text * ppi)
                  RowLocX = 400 + CInt(txtRowLocationX.Text * ppi)
                  RowLocY = 50 + CInt(txtRowLocationY.Text * ppi)

                  'pn.DashStyle = DashStyle.Dash
                  gp.AddRectangle(pathRect)

                  gp.AddEllipse(RowLocX, RowLocY, HoleSize, HoleSize)
                  gp.AddEllipse(RowLocX, RowLocY + yinc, HoleSize, HoleSize)
                  gp.AddEllipse(RowLocX, RowLocY + 2 * yinc, HoleSize, HoleSize)
                  gp.AddEllipse(RowLocX, RowLocY + 3 * yinc, HoleSize, HoleSize)
                  'gp.AddLine(424, 8, 424, 124)
                  'gp.AddLine(424, 28, 95, 124)
                  'gp.AddEllipse(105, 120, 4, 4)
                  'gp.AddLine(80, 18, 424, 114)
                  'gp.AddLine(424, 28, 424, 144)
                  'gp.AddLine(424, 68, 95, 144)
                  'gp.AddLine(80, 134, 90, 134)
                  gp.AddString(txtRowLocationY.Text.ToString, New FontFamily("Arial"), _
      FontStyle.Regular, 10, New Rectangle(350, RowLocY / 2, 35, 12), _
      StringFormat.GenericDefault)
                  g.DrawPath(New Pen(Color.Black, 0.5), gp)

                  gp.Dispose()
                  g.Dispose()

            Catch ex As Exception
                  MsgBox(ex.Message)
            End Try
      End Sub

      Private Sub btnRowLocation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRowLocation.Click
            Try
                  tbpStubLayout.Invalidate()
            Catch ex As Exception
                  MsgBox(ex.Message)
            End Try
      End Sub

Thank you in advance for your consideration.

Sami
tf842Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rovermCommented:
Take a look here:
http://www.vbdotnetheaven.com/Code/Apr2003/002.asp

D'Mzz!
RoverM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rovermCommented:
It's an extensive example in C#, but the VB code should be allmost the same.
0
tf842Author Commented:
Thank you roverm, but I have been there several times. It lists the availble print objects, but doesn't demonstrate them. I did find one site and will review it for code content re printing gdi+. But an initial review left it shy of actually showing how to print gdi+.

Sami
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

tf842Author Commented:
The combination of this site:
http://www.vbdotnetheaven.com/Code/Jun2003/2092.asp
and the first one you mentioned has moved me quite far in the right direction.

I will check out this new one and get back to you.

Thank you,
Sami
0
tf842Author Commented:
roverm,
The microsoft site did not really address the question.

The fact that you are the only one who attempted to answer this question encouraged me enough to look again at a site I previously visited many times. Doing so helped me generate the new search criteria to find the 2nd site. I would like to leave the question for a couple more days, but you are certainly entitled to some of the points. I am still hoping for something a little more in-depth.

Does this seem fair to you?

Thank you,
Sami
0
rovermCommented:
Sure, I will keep looking as well.

GDI+ printing is very nice but not often done.
I posted the link because it explain the raw printing and maybe you could use that.

D'Mzz!
RoverM
0
tf842Author Commented:
Roverm,
What is an alternative to GDI+ printing?

I am basically making a layout of holes and lines. How is something like this usually printed?

I am also unfamiliar with raw printing and am weary of starting down a new path.

Over the past 2 weeks I have probably viewed 100 sites that have had anything to do with GDI+ and printing.

I am looking for Peter Aiken's book re GDI+...Comprehensive tutorial... (I forget the complete name) but it seems to have a 3 - 5 week lag and is not available in ebook form. It sounds like it covers GDI+ printing pretty good.

Thanks for the help and info.

Sami
0
tf842Author Commented:
I have succeeded in printing to the print preview and to paper. Now I have to build a scaling algorythm.
Sami
0
rovermCommented:
Yes, GDI+ most certainly is the way to go, but also not the easiest one.
The only other way I can think of is printing images.

0
tf842Author Commented:
Priniting images is not an option or I would have downloaded a free tool.

My next step is to wrap this thing for my application but it is pretty sketchy right now. The algorithm for scaling should be fun. I have reposted the links to this question and hope for more input.

Sami
0
tf842Author Commented:
Roverm,
This question is getting old, and you are the only one to submit any answers and I appreciate the input and the encouragement.

However, the question was not answered 100%. I would like to propose the following point scenario's for your review:
1) 250 pts and an A rating
2) 500 pts and a B rating

Please let me know which you prefer.

Thank you,
Sami
0
tf842Author Commented:
Naveenkohli,

I currently use a tab on a for as my device context. I draw the 'layout' for the design of a ply of material. It will have rows of holes and perforations.

I can now print the layout to a piece of paper from the values on the tab, and will be printing it directly from the columns of a database shortly. I am writing an algorithm to generate the drawing apart from form specific units of measure. i.e., the dimensions entered will translate into either screen or printer units of measure as required.

My algorithm give me a lot of control, but is time consuming. If you can direct me to a method that will make the conversion between entered, screen and printer units of measure, depending on Roverm's response, I will spit the points or open another question.

Thank you,
Sami
0
rovermCommented:
It's up to you Sami, close it as you want to.

Thanks!

D'Mzz!
RoverM
0
frosteebobCommented:
Try www.about.com or www.planet-source-code.com.

I'm sure you can find a solution there, and even if you can't it's still a great resource.


Frosteebob
0
frosteebobCommented:
tf842,

Try this site:
http://www.vbdotnetheaven.com/

or you can be more specific and go strait to the printing,
and goto:
http://www.vbdotnetheaven.com/Sections/Printing.asp

It's a great vb.net resource.

frosteebob
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.