Click here to Skip to main content
15,899,314 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: FileSystemObject, Trace and Compiled Difference? Pin
Paul Riley19-Aug-03 0:21
Paul Riley19-Aug-03 0:21 
GeneralWord Automation Pin
Emile Jacobs18-Aug-03 6:08
Emile Jacobs18-Aug-03 6:08 
GeneralRe: Word Automation Pin
Nick Seng18-Aug-03 16:16
Nick Seng18-Aug-03 16:16 
GeneralReal-time plots in VB Pin
blaze197818-Aug-03 5:11
blaze197818-Aug-03 5:11 
GeneralRe: Real-time plots in VB Pin
Anonymous27-Aug-03 11:52
Anonymous27-Aug-03 11:52 
GeneralVB6 Pin
totig18-Aug-03 4:34
totig18-Aug-03 4:34 
GeneralRe: VB6 Pin
Nick Seng18-Aug-03 16:05
Nick Seng18-Aug-03 16:05 
GeneralPrinting by VB.NET Pin
rain117818-Aug-03 1:00
rain117818-Aug-03 1:00 
Hi,

I'm want to print the text file from my application. I use the code below and i use dot-matrix printer to print.
However, i find that the printing process is very slow because the printer will print twice per line.

What other method that can be used other than the method below? What other object can be used to print instead of ev.Graphics.DrawString? Or what other setting can used to make the printing faster/print once per row.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim prtdoc As PrintDocument = New PrintDocument()
Dim strDefaultPrinter As String = prtdoc.PrinterSettings.PrinterName
Dim strPrinter As String

For Each strPrinter In PrinterSettings.InstalledPrinters
ComboBox1.Items.Add(strPrinter)
If (strPrinter = strDefaultPrinter) Then
ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf(strPrinter)
End If
Next
End Sub

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = 0
Dim topMargin As Single = 0
Dim line As String = Nothing

' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

' Iterate over the file, printing each line.
While count < linesPerPage
line = streamToPrint.ReadLine()
If line Is Nothing Then
Exit While
End If

yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
yPos, New StringFormat())

count += 1
End While

'If more lines exist, print another page.
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
streamToPrint = New StreamReader("D:\abc.txt")

Try
printFont = New Font("Verdana", 10)
Dim pd As New PrintDocument()
pd.PrinterSettings.PrinterName = ComboBox1.SelectedItem

If (pd.PrinterSettings.IsValid) Then
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Print the document.
pd.Print()
Else
MessageBox.Show("Invalid Printer")
End If

Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
QuestionHow can i send keystrokes to a window in created by another process Pin
Quatl17-Aug-03 17:40
Quatl17-Aug-03 17:40 
AnswerRe: How can i send keystrokes to a window in created by another process Pin
Martin Cross24-Aug-03 23:53
Martin Cross24-Aug-03 23:53 
Generalreading RTF message Body, outlook automation Pin
pnpfriend13-Aug-03 5:00
pnpfriend13-Aug-03 5:00 
QuestionCreating A Bitmap? Pin
GrindAZ12-Aug-03 9:48
GrindAZ12-Aug-03 9:48 
GeneralBuilding a report viewer for Access Pin
sagmam10-Aug-03 22:07
sagmam10-Aug-03 22:07 
GeneralRe: Building a report viewer for Access Pin
mikasa27-Aug-03 2:57
mikasa27-Aug-03 2:57 
QuestionNetScheduleJobAdd API Alternatives? Pin
runtimeware8-Aug-03 13:34
runtimeware8-Aug-03 13:34 
AnswerRe: NetScheduleJobAdd API Alternatives? Pin
Garth J Lancaster8-Aug-03 14:03
professionalGarth J Lancaster8-Aug-03 14:03 
AnswerRe: NetScheduleJobAdd API Alternatives? Pin
Garth J Lancaster8-Aug-03 14:05
professionalGarth J Lancaster8-Aug-03 14:05 
GeneralMicrosoft Word 2000 from the Web Pin
William O'Malley8-Aug-03 4:49
sussWilliam O'Malley8-Aug-03 4:49 
GeneralShaped Forms | vb.NET Pin
Yamarain8-Aug-03 4:01
Yamarain8-Aug-03 4:01 
GeneralRe: Shaped Forms | vb.NET Pin
Ray Cassick8-Aug-03 5:09
Ray Cassick8-Aug-03 5:09 
GeneralThank You Very much!! HELPed alot! Pin
Yamarain8-Aug-03 9:10
Yamarain8-Aug-03 9:10 
GeneralHTTPWebRequest Pin
ami-uhle8-Aug-03 1:12
ami-uhle8-Aug-03 1:12 
GeneralExiting from a menu Pin
b_cochofel8-Aug-03 1:02
b_cochofel8-Aug-03 1:02 
QuestionHow to get the line number Pin
Broker20037-Aug-03 22:21
Broker20037-Aug-03 22:21 
AnswerRe: How to get the line number Pin
Dave Kreskowiak8-Aug-03 4:07
mveDave Kreskowiak8-Aug-03 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.