Connecting Tech Pros Worldwide Forums | Help | Site Map

Printing in vb.net 2005

Newbie
 
Join Date: Mar 2009
Posts: 10
#1: Mar 20 '09
I have a form with one RichText Box int it. The lines in this are formatted differently that is, some lines are in bold letters, some are center aligned and also the font size are different. Currently I am using PrintDialog Box and Print Preview Dialog box to print the Contents of the RichText Box. The problem is when I preview the print contents everything will be displayed in a common font and aligned left. Could someone please help me solve this problem

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,779
#2: Mar 20 '09

re: Printing in vb.net 2005


What does the actual print out look like?
Newbie
 
Join Date: Mar 2009
Posts: 10
#3: Mar 20 '09

re: Printing in vb.net 2005


Quote:

Originally Posted by tlhintoq View Post

What does the actual print out look like?

Actual Data to Print
Heading
Sub Heading

Lines of Text



But it Displays

Heading
Sub Heading
Lines of Text
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,779
#4: Mar 20 '09

re: Printing in vb.net 2005


So you are saying the actual paper print is matching the PrintPreview on screen: No formatting for alignment or style; all is left and plain??
Newbie
 
Join Date: Mar 2009
Posts: 10
#5: Mar 21 '09

re: Printing in vb.net 2005


Quote:

Originally Posted by tlhintoq View Post

So you are saying the actual paper print is matching the PrintPreview on screen: No formatting for alignment or style; all is left and plain??

Yes. Could you please tell me how to print along with formatting for alignment and style.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,779
#6: Mar 21 '09

re: Printing in vb.net 2005


Could you post:
A) The code you are using to fill the RichTextBox
B) The code you are using to call the PrintPreview
Newbie
 
Join Date: Mar 2009
Posts: 10
#7: Mar 21 '09

re: Printing in vb.net 2005


Quote:

Originally Posted by tlhintoq View Post

Could you post:
A) The code you are using to fill the RichTextBox
B) The code you are using to call the PrintPreview

I have replaced the richtext box with labels and textboxes. Now I am printing the contents of each control seperately. The code I am using now is below. This works to some extent but the alignment is not proper. Is there any other way of doing this.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
  2.         Dim Page As String
  3.         Page = Me.Label1.Text
  4.         e.Graphics.DrawString(Page, Label1.Font, Brushes.Black, Me.Label1.Location.X, Me.Label1.Location.Y)
  5.  
  6.         Page = Me.Label2.Text
  7.         e.Graphics.DrawString(Page, Label2.Font, Brushes.Blue, Me.Label2.Location.X, Me.Label2.Location.Y)
  8.  
  9.         Page = Me.TextBox1.Text
  10.         e.Graphics.DrawString(Page, TextBox1.Font, Brushes.Black, Me.TextBox1.Location.X, Me.TextBox1.Location.Y)
  11.  
  12.         e.HasMorePages = False
  13.  
  14.     End Sub
  15.  
Newbie
 
Join Date: Mar 2009
Posts: 10
#8: Mar 23 '09

re: Printing in vb.net 2005


Someone please tell me how can I print the contents of different controls in vb.net2005
Reply