Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing VB6 form.print method

Status
Not open for further replies.
Here's the code from MS:

Public Sub DrawString()
Dim formGraphics As System.Drawing.Graphics = Me.CreateGraphics()
Dim drawString As String = "Sample Text"
Dim drawFont As New System.Drawing.Font("Arial", 16)
Dim drawBrush As New _
System.Drawing.SolidBrush(System.Drawing.Color.Black)
Dim x As Single = 150.0
Dim y As Single = 50.0
Dim drawFormat As New System.Drawing.StringFormat()
formGraphics.DrawString(drawString, drawFont, drawBrush, _
x, y, drawFormat)
drawFont.Dispose()
drawBrush.Dispose()
formGraphics.Dispose()
End Sub


You were looking at printing

Phan
 
Thanks a lot, it works. I actually don't know yet how to override the OnPaint event with this sub but I made it work by calling the sub from an command botton click event.

How one create a form (baseform) OnPaint handler?

Thanks again
Dan
 
Hi Dan,

You can write your code in the Form's Paint event method using e as your graphics object, like this:

Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
    Handles MyBase.Paint

    e.Graphics.DrawString("Hello", New Font("Arial", 18.0, _
    FontStyle.Regular), New SolidBrush(Color.Black), 10, 10)

End Sub

T0AD

There's a thin line between genius, and insanity!
 
Thanks it works but I had to chane to:

e.Graphics.DrawString("Hello", New System.Drawing.Font("Arial", 16), New SolidBrush(Color.Black), 10, 10)

for some reason.

FontStyle.regular cause me syntax error.

Thanks again
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top