Click here to Skip to main content
15,905,785 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHTML report in VB 6.0 Pin
tusar12311-Dec-05 20:15
tusar12311-Dec-05 20:15 
AnswerRe: HTML report in VB 6.0 Pin
uktrips00711-Dec-05 20:33
uktrips00711-Dec-05 20:33 
AnswerRe: HTML report in VB 6.0 Pin
MarcelErz12-Dec-05 4:32
MarcelErz12-Dec-05 4:32 
QuestionPrinting with vb.net (Urgent) Pin
HemaRawat11-Dec-05 20:06
HemaRawat11-Dec-05 20:06 
AnswerRe: Printing with vb.net (Urgent) Pin
uktrips00711-Dec-05 20:53
uktrips00711-Dec-05 20:53 
GeneralRe: Printing with vb.net (Urgent) Pin
HemaRawat11-Dec-05 21:05
HemaRawat11-Dec-05 21:05 
GeneralRe: Printing with vb.net (Urgent) Pin
uktrips00711-Dec-05 23:16
uktrips00711-Dec-05 23:16 
AnswerRe: Printing with vb.net (Urgent) Pin
Briga12-Dec-05 1:37
Briga12-Dec-05 1:37 
The formally correct solution is probably the best one although is a bit more complex. But not too much.

You have better to use a PrintDocument class. There's plenty of documentation and samples on MSDN and here as well.

To summarize:

1) Create a desgin time a printdocument in the form (i.e. called pDoc)
2) Double click on it to open the editor in the printing function
3) Write the code to print your data (***)
4) From the button invoke the pDoc.Print method.

(***) I'm not able to write the full code you need but it should be something with:

e.graphics.drawstring for each text you want to print
e.graphics.drawimage for each image you want to print.

Here's an example from the documentation

Public Class PrintingExample
    Inherits System.Windows.Forms.Form
    Private components As System.ComponentModel.Container
    Private printButton As System.Windows.Forms.Button
    Private printFont As Font
    Private streamToPrint As StreamReader
    
    Public Sub New()
        ' The Windows Forms Designer requires the following call.
        InitializeComponent()
    End Sub    
    
    ' The Click event is raised when the user clicks the Print button.
    Private Sub printButton_Click(sender As Object, e As EventArgs)
        Try
            streamToPrint = New StreamReader("C:\My Documents\MyFile.txt")
            Try
                printFont = New Font("Arial", 10)
                Dim pd As New PrintDocument()
                AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
                pd.Print()
            Finally
                streamToPrint.Close()
            End Try
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub    
    
    ' The PrintPage event is raised for each page to be printed.
    Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs)
        Dim linesPerPage As Single = 0
        Dim yPos As Single = 0
        Dim count As Integer = 0
        Dim leftMargin As Single = ev.MarginBounds.Left
        Dim topMargin As Single = ev.MarginBounds.Top
        Dim line As String = Nothing
        
        ' Calculate the number of lines per page.
        linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
        
        ' Print each line of the file.
        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
     
    
    ' The Windows Forms Designer requires the following procedure.
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.printButton = New System.Windows.Forms.Button()
        
        Me.ClientSize = New System.Drawing.Size(504, 381)
        Me.Text = "Print Example"
        
        printButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        printButton.Location = New System.Drawing.Point(32, 110)
        printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        printButton.TabIndex = 0
        printButton.Text = "Print the file."
        printButton.Size = New System.Drawing.Size(136, 40)
        AddHandler printButton.Click, AddressOf printButton_Click
        
        Me.Controls.Add(printButton)
    End Sub 

    ' This is the main entry point for the application.    
    Public Shared Sub Main()
        Application.Run(New PrintingExample())
    End Sub

End Class

GeneralRe: Printing with vb.net (Urgent) Pin
HemaRawat12-Dec-05 17:33
HemaRawat12-Dec-05 17:33 
QuestionTooltip for datagridview Pin
LongNguyen11-Dec-05 18:52
LongNguyen11-Dec-05 18:52 
AnswerRe: Tooltip for datagridview Pin
uktrips00711-Dec-05 21:02
uktrips00711-Dec-05 21:02 
QuestionRe: Tooltip for datagridview Pin
LongNguyen11-Dec-05 22:25
LongNguyen11-Dec-05 22:25 
QuestionSound Pin
Polymorpher11-Dec-05 17:57
Polymorpher11-Dec-05 17:57 
AnswerRe: Sound Pin
Briga11-Dec-05 22:40
Briga11-Dec-05 22:40 
GeneralRe: Sound Pin
Polymorpher13-Dec-05 15:42
Polymorpher13-Dec-05 15:42 
QuestionCreating windows service in vb.net Pin
tusar12311-Dec-05 17:40
tusar12311-Dec-05 17:40 
AnswerRe: Creating windows service in vb.net Pin
Steve Pullan11-Dec-05 17:46
Steve Pullan11-Dec-05 17:46 
Questionpassword setting ...for pocket pc Pin
eileenpp11-Dec-05 16:16
eileenpp11-Dec-05 16:16 
QuestionCommon Language Runtime Debugging Services(error) Pin
Mazitan11-Dec-05 15:43
Mazitan11-Dec-05 15:43 
AnswerRe: Common Language Runtime Debugging Services(error) Pin
Steve Pullan11-Dec-05 17:41
Steve Pullan11-Dec-05 17:41 
GeneralRe: Common Language Runtime Debugging Services(error) Pin
Mazitan12-Dec-05 13:24
Mazitan12-Dec-05 13:24 
GeneralRe: Common Language Runtime Debugging Services(error) Pin
Steve Pullan12-Dec-05 14:04
Steve Pullan12-Dec-05 14:04 
GeneralRe: Common Language Runtime Debugging Services(error) Pin
Mazitan12-Dec-05 14:38
Mazitan12-Dec-05 14:38 
GeneralRe: Common Language Runtime Debugging Services(error) Pin
Steve Pullan12-Dec-05 14:58
Steve Pullan12-Dec-05 14:58 
GeneralRe: Common Language Runtime Debugging Services(error) Pin
Mazitan12-Dec-05 15:06
Mazitan12-Dec-05 15:06 

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.