Print text to a form
IN Vb 6.0, using the Print command would print whatever text you put onto the form. Im wondering how you would do that same thing in VB2005 because apparently the command had changed...
thank you
IN Vb 6.0, using the Print command would print whatever text you put onto the form. Im wondering how you would do that same thing in VB2005 because apparently the command had changed...
thank you
I don't believe that there is anything comparable without using GDI. The easiest thing to do is add a label to the form and write text into it.
Hope this helps.
Hi-
Relief is on the way! Stay tuned for an anouncement that is going to make life much better for PrintForm scenarios... very soon.
Best,
Paul Yuknewicz
Lead Program Manager
Visual Basic
This particular person did not ask about printing a form, but rather how to print text to a form. I think that is a different question.
If the question *was* how to print a form, here is how I do it:
PrivateSub ProcessPrintPage(ByVal e As System.Drawing.Printing.PrintPageEventArgs)Dim r As RectangleDim frmToPrint As Form = Me.ActiveMdiChild' Confirm that a form has been defined for printing If frmToPrint IsNothingThene.Cancel =
True ThrowNew InvalidOperationException("There is no active MDI child")EndIf ' Define a (0,0) based rectangle for the imager =
New Rectangle(0, 0, frmToPrint.Width, frmToPrint.Height)' Create the bitmap of the image Dim b AsNew Bitmap(frmToPrint.Width, frmToPrint.Height)frmToPrint.DrawToBitmap(b, r)
' Draw the bitmap to the printdocument scaled ' to the printer's margins, but keeping the ' same aspect ratio Dim iNewHeight AsInteger, iNewWidth AsInteger Dim dPrinterAspectRatio AsDouble = e.MarginBounds.Height / e.MarginBounds.WidthDim dFormAspectRatio AsDouble = frmToPrint.Height / frmToPrint.WidthIf dFormAspectRatio > dPrinterAspectRatio Then ' Form has bigger height, so set the height to max and scaleiNewHeight = e.MarginBounds.Height
iNewWidth =
CType(e.MarginBounds.Height / dFormAspectRatio, Integer)Else ' Form has a bigger width, so set the width to max and scaleiNewHeight =
CType(e.MarginBounds.Width * dFormAspectRatio, Integer)iNewWidth = e.MarginBounds.Width
EndIf ' Define a new rectangle for the scaled imager =
New Rectangle(e.MarginBounds.X, e.MarginBounds.Y, iNewWidth, iNewHeight)e.Graphics.DrawImage(b, r)
EndSub
P.S. This works in VS 2005...
For those of you who were looking for a Form.Print or PrintForm feature, here it is!
http://msdn.microsoft.com/vbasic/downloads/powerpacks/default.aspx
Hi DeborahK,
This posting was very helpful in trying to get a form scaled and printed. Thank you for the posting. I've come across one little difficulty with it that I hope you can assist me with and resolve. The first request goes thru very quickly. Subsequent prints take longer and longer.I have discovered by putting a Beep() statement and the beginning of the subroutine, the first it goes through the subroutine it beeps once, each time the subroutine is called again it beeps an additional time.So, by the time you’ve called the routine the tenth time you will hear 10 beeps.Is there something I need to clear or reset to eliminate this issue.I’ve also tried message boxes and see the same results.The first time ran you will the box once then an additional message box each time a print request is generated.
Thanks for the posting.I look forward to your response and solution.