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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textheight from VB6 not recognized in vb.net 1

Status
Not open for further replies.

joeschoe

Programmer
Jan 13, 2002
67
IL
I am converting an application using mshflexgrid from vb6 to vb.net.
I had used a routine to resize the row height.
It originally had the text:

'Get the height of the text in the textbox
HeightOfLine = frmGrid.TextHeight(frmGrid.Text1.Text)

vb.net complains that textheight is not a valid property? Any suggestions as to how I can complete this updrade?
 
here are a couple of functions that I use to measure strings - can't remember where i got these from (I can tell from the style that it's someone else's code). I would also recommend doing a search for "MeasureString" in this forum as there are a couple of links that might be useful.
Code:
		Shared Function StringWidth(ByVal Text As String, _
		 ByVal useFont As Font) As Double

			Dim b As Bitmap
			Dim g As Graphics
			Dim w As Double

			' Compute the string dimensions in the given font
			b = New Bitmap(1, 1, Imaging.PixelFormat.Format32bppArgb)
			g = Graphics.FromImage(b)
			Dim stringSize As SizeF = g.MeasureString(Text, useFont)
			w = stringSize.Width
			g.Dispose()
			b.Dispose()
			Return Maths.RoundUp(w)

		End Function

		Shared Function StringHeight(ByVal Text As String, _
		  ByVal useFont As Font) As Double

			Dim b As Bitmap
			Dim g As Graphics
			Dim h As Double

			' Compute the string dimensions in the given font
			b = New Bitmap(1, 1, Imaging.PixelFormat.Format32bppArgb)
			g = Graphics.FromImage(b)
			Dim stringSize As SizeF = g.MeasureString(Text, useFont)
			h = stringSize.Height
			g.Dispose()
			b.Dispose()
			Return Maths.RoundUp(h)

		End Function
 
Techsmith: Thanks for your code. I have added your code to my system, but I still have a list of 100s of errors to clean up before I can know if the routines do what I need.

Chrissie1: I am still using MSHflexgrid, there was so much to learn in the converting to vb.net that I changed as little as possible.
 
Then I see no reason why that propertie wouldn't be there anymore. Perhaps you forgot to set a reference or perhaps MS changed the type.

BTW Going to vb.net and not changing your code for the better has no sense whatsoever you wold have been better staying with vb6. But it's your program.

Christiaan Baes
Belgium

"My new site" - Me
 
You are correct, chrissie1.
The program is only the first part of a larger system. I want to train new programmers to help me in the future development and they don't want to start learning vb6 when vb.net seems to be the vb of the near future.
 
Just spotted the output type of those two functions (StringHeight and StringWidth) should be Integer not Double - to avoid implicit conversions from double to integer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top