|
-
Feb 23rd, 2008, 11:27 AM
#1
Thread Starter
Lively Member
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
-
Feb 23rd, 2008, 11:30 AM
#2
Re: Print Preview
use e.graphics.drawimage in the same place you're using e.Graphics.DrawString
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 23rd, 2008, 02:44 PM
#3
Thread Starter
Lively Member
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?
-
Feb 23rd, 2008, 03:34 PM
#4
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 23rd, 2008, 04:02 PM
#5
Thread Starter
Lively Member
Re: Print Preview
Thank you i got it working good.
-
Feb 24th, 2008, 02:39 AM
#6
Thread Starter
Lively Member
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?
-
Feb 24th, 2008, 03:08 AM
#7
Re: Print Preview
vb Code:
Public Class Form1
Dim img As Bitmap
Private Sub addPicture()
If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
img = 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()
End If
End Sub
Private Sub print()
' Create the document and attach an event handler.
Dim MyDoc As New Printing.PrintDocument()
AddHandler MyDoc.PrintPage, AddressOf MyDoc_PrintPage
MyDoc.Print()
My.Application.DoEvents()
End Sub
Private Sub MyDoc_PrintPage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
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
e.Graphics.DrawImage(img, 10, 20)
'you might have to modify the way your text prints
'i haven't tried printing a complete rtb text
End Sub
end class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 24th, 2008, 03:31 AM
#8
Thread Starter
Lively Member
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
-
Feb 24th, 2008, 04:48 AM
#9
Re: Print Preview
you'll have to show me your print preview code
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 24th, 2008, 12:27 PM
#10
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|