Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 22nd, 2014, 11:12 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default Display a string on a Form

I converted an old VB 6 program to VB 2008. What the program does is to read a database table and depending on data requirements, it is supposed to display the record like first name and last name on to the form. With VB 6.0 I just used the print method currentx and currenty but with VB 2008 I can't get them to print. I have searched around and saw CreateGraphics so I used it to replace the print statement from VB 6.0. After doing this, I can only see a blank form and the records are not getting displayed.

Below is the original VB 6.0 code.

Private Sub PrintHeading(strstring, intColumn, introw, fontsize)
frmPrintBenefits.Height = 15000
frmPrintBenefits.Width = 11500
frmPrintBenefits.CurrentX = intColumn
frmPrintBenefits.CurrentY = introw
frmPrintBenefits.fontsize = fontsize
frmPrintBenefits.FontBold = True
frmPrintBenefits.Print strstring
End Sub
Here is the code from VB 2008 after it was converted. I used drawstring to print or display the records on the form. I thought this would work but I am seeing a blank form.

Friend Class frmPrintBenefits
   Inherits System.Windows.Forms.Form
   Dim g As Graphics = Me.CreateGraphics
   Dim strstring as String
   Dim intColumn as Integer
   Dim intRow as Integer
   Dim fontsize as Double
   Private Sub PrintHeading(ByRef strstring As String, ByRef intColumn AsInteger, ByRef introw AsInteger, ByRef fontsize As Integer)
   Me.Height = VB6.TwipsToPixelsY(15000)
   Me.Width = VB6.TwipsToPixelsX(11500)
   Me.Font = VB6.FontChangeSize(Me.Font, fontsize)
   Me.Font = VB6.FontChangeBold(Me.Font, True)
   g.DrawString(strstring, Font, Brushes.Black, intColumn, introw)
   End Sub
End Class
Am I using the wrong syntax?


Last edited by jmss66; April 22nd, 2014 at 11:21 AM..
Old April 22nd, 2014, 03:49 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

If you don't *have* to draw, but just want to output the text, you can also add a Label to the form and assign text to it.

To add the Label, just drag one from the Toolbox. Then you can assign text to it like this:

label1.Text = "Whatever you want"

Hope this helps,

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Data Will Not Display When I Click On Display Button sprdave BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 12 February 13th, 2011 12:09 AM
Display the Length of the String kulfi BOOK: Beginning Microsoft Visual Basic 2010 15 December 30th, 2010 04:41 PM
Display String value for given period cloudsuser JSP Basics 1 June 25th, 2010 11:28 PM
Display attribute and particular string in different color rangeshram XSLT 1 October 30th, 2009 06:49 PM
Display 0 currency as Null String echovue Access 5 August 11th, 2005 02:33 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.