Results 1 to 10 of 10

Thread: Print Preview

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    74

    Print Preview

    I have a Text box with some text and I have a print preview button that preview the text

    Code:
    Using titlefont As New System.Drawing.Font("Arial", 18, FontStyle.Bold)
                e.Graphics.DrawString("File Printout", titlefont, Brushes.Black, 370, 27)
            End Using
            Using datafont As New System.Drawing.Font("Arial", 10, FontStyle.Regular)
                e.Graphics.DrawString(Me.textMainTextBox.Text, datafont, Brushes.Black, 10, 130)
    
    End Using
    Also i have a button to add a picture to the text box, along with the text

    Code:
    Me.OpenFileDialog1.Filter = "JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|Gif Images (*.gif)|*.gif|Bitmaps (*.bmp)|*.bmp"
            Me.OpenFileDialog1.FilterIndex = 1
            If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim img As New System.Drawing.Bitmap(Me.OpenFileDialog1.FileName)
                Clipboard.SetImage(img)
                textMainTextBox.Paste()
    what i want to do is have the picture display along with the test in the print preview
    this is not part of my Assignment
    any help is very appreciated
    .C

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Print Preview

    use e.graphics.drawimage in the same place you're using e.Graphics.DrawString

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    74

    Re: Print Preview

    Im a little lost on how to complete this
    Code:
     e.Graphics.DrawImage(Clipboard.GetData(), 10, 20)
    does get data need something?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Print Preview

    when you load the image into the rtb originally, change the dim img as new bitmap from a local variable to a class level variable then you'll have a copy of the image to print

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    74

    Re: Print Preview

    Thank you i got it working good.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    74

    Re: Print Preview

    I didnt do the way you suggested and im having problems.
    Code:
    If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim img As New System.Drawing.Bitmap(Me.OpenFileDialog1.FileName)
    
                Clipboard.SetImage(img) ' set the image in the clipboard so we can paste it in the text box
                textMainTextBox.Paste()
    how can i do what you suggested?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Print Preview

    vb Code:
    1. Public Class Form1
    2.  
    3.     Dim img As Bitmap
    4.  
    5.     Private Sub addPicture()
    6.         If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    7.             img = New Bitmap(Me.OpenFileDialog1.FileName)
    8.  
    9.             Clipboard.SetImage(img) ' set the image in the clipboard so we can paste it in the text box
    10.             textMainTextBox.Paste()
    11.         End If
    12.     End Sub
    13.  
    14.     Private Sub print()
    15.         ' Create the document and attach an event handler.
    16.         Dim MyDoc As New Printing.PrintDocument()
    17.         AddHandler MyDoc.PrintPage, AddressOf MyDoc_PrintPage
    18.  
    19.         MyDoc.Print()
    20.         My.Application.DoEvents()
    21.  
    22.     End Sub
    23.  
    24.     Private Sub MyDoc_PrintPage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
    25.         Using titlefont As New System.Drawing.Font("Arial", 18, FontStyle.Bold)
    26.             e.Graphics.DrawString("File Printout", titlefont, Brushes.Black, 370, 27)
    27.         End Using
    28.         Using datafont As New System.Drawing.Font("Arial", 10, FontStyle.Regular)
    29.             e.Graphics.DrawString(Me.textMainTextBox.Text, datafont, Brushes.Black, 10, 130)
    30.         End Using
    31.         e.Graphics.DrawImage(img, 10, 20)
    32.         'you might have to modify the way your text prints
    33.         'i haven't tried printing a complete rtb text
    34.     End Sub
    35.  
    36. end class

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    74

    Re: Print Preview

    ok i can select the bitmap and paste it into the text box
    Code:
    If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim img As New Bitmap(Me.OpenFileDialog1.FileName)
    
                Clipboard.SetImage(img) ' set the image in the clipboard so we can paste it in the text box
                textMainTextBox.Paste()
    and when i do a print preview the image shows up fine and prints
    so i have cpde to clear everything
    Code:
    Case 4
                    Me.textMainTextBox.ForeColor = Color.Empty
                    Me.ToolstripFontDialog1.Reset()
                    Me.textMainTextBox.Font = Me.ToolstripFontDialog1.Font
                    Me.textMainTextBox.BackColor = Color.Empty
                    Me.textMainTextBox.Text = Nothing
                    Clipboard.Clear() ' clear the image from the clipboard
    but when i add a new images the old one shows up on the print preview
    but when i go to print the new bimap will show

    Code:
    Using titlefont As New System.Drawing.Font("Arial", 18, FontStyle.Bold)
                e.Graphics.DrawString("File Printout", titlefont, Brushes.Black, 370, 27)
            End Using
            Using datafont As New System.Drawing.Font("Arial", 10, FontStyle.Regular)
                e.Graphics.DrawString(Me.textMainTextBox.Text, datafont, Brushes.Black, 10, 200)
    
            End Using
    
            If img Is Nothing Then
    
            Else
    
                e.Graphics.DrawImage(img, 10, 100) ' print preview the picture we assigned to the pic1.image
            End If

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Print Preview

    you'll have to show me your print preview code

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    74

    Re: Print Preview

    here it is
    Code:
     Try
                Me.PrintPreviewDialog.Document = Me.DocumentToPrint
    
                PrintPreviewDialog.ShowDialog()
    
            Catch es As Exception
                MessageBox.Show(es.Message)
            End Try

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width