VB Dot NET Forum: print tutorial - VB Dot NET Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

print tutorial

#1 User is offline   vbnet_noob Icon

  • Moderator
  • PipPipPip
Group:
Mods
Posts:
442
Joined:
19-January 07
Gender:
Male

VB Knowledge: Decent
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows 7 x64

Posted 19 January 2007 - 03:02 PM

hi,

I'd like to know about the print controls and how to use them.

thank you.
0

#2 User is offline   Dylan Icon

  • Advanced Member
  • PipPipPip
Group:
Root Admin
Posts:
1,058
Joined:
12-January 07
Location:
Atlanta, GA, USA
Interests:
Computer Science, Operating Systems

VB Knowledge: Experienced
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Mac OS X

Posted 19 January 2007 - 03:52 PM

I will write you a tutorial on printing when I arrive back to my house.
0

#3 User is offline   DeathKindler Icon

  • Moderator
  • PipPipPip
Group:
Mods
Posts:
452
Joined:
09-January 07
Gender:
Male
Location:
PA, USA
Interests:
Music, Web Programming and Design, Desktop Programming, Hacking, Reading, Modding, Basic Electrical Engineering

VB Knowledge: Experienced
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows 7 x64

Posted 19 January 2007 - 03:54 PM

View Postvbnet_noob, on Jan 19 2007, 03:02 PM, said:

hi,

I'd like to know about the print controls and how to use them.

thank you.


MSDN's 101 VB Dot Net samples had a thing on it if you want to look at some code. I've attached the file to my post.

VB Dot Net's print controls are simple to use. They make use of system.drawing for just about everything, I myself know very little on the subject though.

Game Tag: DeathKindler
Hit me up on Leaf Networks, Xlink Kai, or Xbox Connect.
0

#4 User is offline   Dylan Icon

  • Advanced Member
  • PipPipPip
Group:
Root Admin
Posts:
1,058
Joined:
12-January 07
Location:
Atlanta, GA, USA
Interests:
Computer Science, Operating Systems

VB Knowledge: Experienced
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Mac OS X

Posted 19 January 2007 - 04:32 PM

DeathKindler, the attachment didn't work. Here is the example from the 101 examples in .zip format.

Attached File(s)


0

#5 User is offline   vbnet_noob Icon

  • Moderator
  • PipPipPip
Group:
Mods
Posts:
442
Joined:
19-January 07
Gender:
Male

VB Knowledge: Decent
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows 7 x64

Posted 19 January 2007 - 11:31 PM

I have the 101 thing.

I'll have to go look at it tonight.

well it have print preview as well?
0

#6 User is offline   DeathKindler Icon

  • Moderator
  • PipPipPip
Group:
Mods
Posts:
452
Joined:
09-January 07
Gender:
Male
Location:
PA, USA
Interests:
Music, Web Programming and Design, Desktop Programming, Hacking, Reading, Modding, Basic Electrical Engineering

VB Knowledge: Experienced
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows 7 x64

Posted 20 January 2007 - 02:57 PM

View Postvbnet_noob, on Jan 19 2007, 11:31 PM, said:

I have the 101 thing.

I'll have to go look at it tonight.

well it have print preview as well?


Yea, It will. Sorry about the broken attachment... my bad...

It'll have the actual printing and a print preview example in it, but its made mainly for text printing but you could get it to print a form or an image if you needed to.

Game Tag: DeathKindler
Hit me up on Leaf Networks, Xlink Kai, or Xbox Connect.
0

#7 User is offline   Dylan Icon

  • Advanced Member
  • PipPipPip
Group:
Root Admin
Posts:
1,058
Joined:
12-January 07
Location:
Atlanta, GA, USA
Interests:
Computer Science, Operating Systems

VB Knowledge: Experienced
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Mac OS X

Posted 02 August 2007 - 10:41 AM

Vbnet_noob, what control are you trying to add a PrintPreview to?
0

#8 User is offline   FDA Icon

  • Newbie
  • Pip
Group:
Members
Posts:
1
Joined:
17-January 08

VB Knowledge: Experienced
VB Version:
VB 2005 (.NET 2.0)

Post icon  Posted 17 January 2008 - 08:53 AM

Hi, I am developing a report to be printed with PrintDocument class.The problem is some parts of this report are iterated and some not.In fact report consist of three sections.The top and buttom sections are always the same but middle section is being produced from Database.The problem is how to print more than one page, I tried to use HasMorePages but somehow I think I am doing something wrong.



I need to :

1-Print top and buttom sections more than one time if the data in middle section won't fit in its specified area.

2-Be able to access each new page, if possible.That way I can repeat itereated sections and write down the continued middle section.

3-Control the behaviour of HasMorePages in order to print middle section succefully.



Since this development is company-based the code I am gonna attach is protected.It cannot be used , distributed and altered under any circumstances.I am using the following code.






Code BlockWhile (intLastPrintedCell < strText.GetUpperBound(0))

e.HasMorePages = True

If Not intLastPrintedCell > 0 Then

Dim intDistance As Integer = 0

For i As Integer = strText.GetLowerBound(0) To strText.GetUpperBound(0)

If intDistance <= intSplit2Distance Then

text = strText(i)

If chkShowTextInBox.Checked = True Then

e.Graphics.DrawRectangle(Pens.Black, rea("FLEFT"), rea("FTOP") + intSplit1Distance, rea("FWIDTH"), rea("FHEIGHT"))

End If

rec.X = rea("FLEFT")

rec.Y = rea("FTOP") + intSplit1Distance + intDistance

rec.Height = rea("FHEIGHT")

rec.Width = rea("FWIDTH")

e.Graphics.DrawString(text, printFont, brsh, rec, frmt)

intDistance = intDistance + rec.Height + intFieldDistance

'e.HasMorePages = False

intLastPrintedCell = i

Else

'intLastPrintedCell = i

Exit For

'

End If

Next

Else

Dim intDistance As Integer = 0

For i As Integer = intLastPrintedCell To strText.GetUpperBound(0)

If intDistance < intSplit2Distance Then

text = strText(i)

If chkShowTextInBox.Checked = True Then

e.Graphics.DrawRectangle(Pens.Black, rea("FLEFT"), rea("FTOP") + intSplit1Distance, rea("FWIDTH"), rea("FHEIGHT"))

End If

rec.X = rea("FLEFT")

rec.Y = rea("FTOP") + intSplit1Distance + intDistance

rec.Height = rea("FHEIGHT")

rec.Width = rea("FWIDTH")

e.Graphics.DrawString(text, printFont, brsh, rec, frmt)

intDistance = intDistance + rec.Height + intFieldDistance

'e.HasMorePages = False

intLastPrintedCell = i

Else

'e.HasMorePages = True

'intLastPrintedCell = i + 1

'

End If

Next

End If

End While

e.HasMorePages = False






I'd apperciate any help.If you have more information about the code contact me directly.



Remember!This code snippet is protected by international laws.
0

#9 User is offline   conorsteel Icon

  • Advanced Member
  • PipPipPip
Group:
Members
Posts:
348
Joined:
26-May 08
Location:
Kilmarnock, Scotland

VB Knowledge: Decent
VB Version:
VB 2005 (.NET 2.0)
OS: Windows Vista

Post icon  Posted 14 June 2008 - 11:23 AM

To Print the entire form

Add a Button, PrintForm Controls

Double Click the Button and add the following code.

dim reply
reply = MsgBox("Do you really want to PRINT?", 52)
Rem 52 is made up of 4 for Yes/No and 48 for the exclamation mark icon
If reply = 6 Then
	PrintForm1.Print()
End If


I think this works, it did for me, it depends what version of VB you use i think. Due to experiences.

CS
Conor Steel
0

#10 User is offline   programmer-in-training Icon

  • Experienced Member
  • PipPipPip
Group:
Mods
Posts:
1,954
Joined:
20-October 07
Gender:
Male
Interests:
Desktop/web programming, calculus, particle physics, electrical engineering

VB Knowledge: Experienced
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows 7 x64

Posted 14 June 2008 - 02:09 PM

You can get rid of a variable and two lines by writing:
If MsgBox("Do you really want to PRINT?", 52) = 6 Then PrintForm1.Print()

Also, you generally should not be cryptic; better to err on the other side:
If MsgBox("Do you really want to PRINT?", MsgBoxStyle.YesNo Or MsgBoxStyle.Exclamation) = MsgBoxResult.Yes Then PrintForm1.Print()


And I don't prefer this because it's longer, but you could also use the main message box function:
If MessageBox.Show("Do you really want to PRINT?", "Print", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Yes Then PrintForm1.Print()

0

#11 User is offline   conorsteel Icon

  • Advanced Member
  • PipPipPip
Group:
Members
Posts:
348
Joined:
26-May 08
Location:
Kilmarnock, Scotland

VB Knowledge: Decent
VB Version:
VB 2005 (.NET 2.0)
OS: Windows Vista

Post icon  Posted 18 June 2008 - 03:53 PM

View PostFDA, on Jan 17 2008, 02:53 PM, said:

Remember!This code snippet is protected by international laws.


Don't lie, the government can't protect programming code snippets. They can however prtoect your prigrams.
Conor Steel
0

#12 User is offline   programmer-in-training Icon

  • Experienced Member
  • PipPipPip
Group:
Mods
Posts:
1,954
Joined:
20-October 07
Gender:
Male
Interests:
Desktop/web programming, calculus, particle physics, electrical engineering

VB Knowledge: Experienced
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows 7 x64

Posted 18 June 2008 - 07:57 PM

Quote

Remember!This code snippet is protected by international laws.
Citation needed.

Quote

Don't lie, the government can't protect programming code snippets. They can however prtoect your prigrams.
Citation needed.
0

#13 User is offline   chan_ricca Icon

  • Newbie
  • Pip
Group:
Members
Posts:
1
Joined:
30-December 08

VB Knowledge: Beginner
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows Vista

Posted 30 December 2008 - 07:46 AM

Need Help in printing and using the report viewer..

I'm a beginner in vb....my innitial project does not involve neither access nor database at all...I would like to print forms and data that the user enters. Is there any simple step by step tutorials ??
0

#14 User is offline   luii Icon

  • Newbie
  • Pip
Group:
Members
Posts:
1
Joined:
31-March 09

VB Knowledge: Beginner
VB Version:
VB 2008 (.NET 3.0/3.5)
OS: Windows Vista x64

Posted 31 March 2009 - 03:40 PM

Hi

Im looking for some kind of tutorial aswell..
Its about making a very simple program, that can copy 4 textboxes of text on a label(5x8cm) and then be printed by a old labelprinter i just got..
Another thing, can you even make these printing things in VB2008 express?
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users