Solved

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

Posted on 2003-11-04
17
498 Views
Last Modified: 2008-01-16
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
0
Comment
Question by:tf842
  • 8
  • 6
  • 2
17 Comments
 
LVL 12

Accepted Solution

by:
roverm earned 500 total points
ID: 9714881
Take a look here:
http://www.vbdotnetheaven.com/Code/Apr2003/002.asp

D'Mzz!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 9714884
It's an extensive example in C#, but the VB code should be allmost the same.
0
 

Author Comment

by:tf842
ID: 9716663
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
 
LVL 12

Expert Comment

by:roverm
ID: 9718167
0
 

Author Comment

by:tf842
ID: 9718434
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
 

Author Comment

by:tf842
ID: 9718483
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
 
LVL 12

Expert Comment

by:roverm
ID: 9720617
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
 

Author Comment

by:tf842
ID: 9721440
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:tf842
ID: 9721444
I have succeeded in printing to the print preview and to paper. Now I have to build a scaling algorythm.
Sami
0
 
LVL 12

Expert Comment

by:roverm
ID: 9721529
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
 

Author Comment

by:tf842
ID: 9721737
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
 

Author Comment

by:tf842
ID: 9747284
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
 

Author Comment

by:tf842
ID: 9747356
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
 
LVL 12

Expert Comment

by:roverm
ID: 9747461
It's up to you Sami, close it as you want to.

Thanks!

D'Mzz!
RoverM
0
 

Expert Comment

by:frosteebob
ID: 10032878
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
 

Expert Comment

by:frosteebob
ID: 10035113
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual xHarbour 1 76
 shows up in Outlook, not OWA or on phone 3 58
delphi parse string to params 3 81
move one pixel 4 41
Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now