unsopported SizeF in .net compact? (determine label text size)

  • Thread starter Thread starter Jacco
  • Start date Start date
J

Jacco

I wanted to see if a texts fits into a label and I created this code:

With lblOptionC1

Dim gfx As Graphics = picMainScreen.CreateGraphics

Dim FontSize As New System.Drawing.SizeF

FontSize = gfx.MeasureString(.Text, .Font)



But the line "Dim FontSize..." results in an error which says "Unsopported"
although the help says that it should work. Any clues?



Thanx!


Jacco
 
Hi Tim,

I tried the folowing now (again, code copied from the help-file):
Dim gfx As Graphics = picMainScreen.CreateGraphics

Dim lblSize As Size = gfx.MeasureString(.Text, .Font).ToSize


and the 'green line' shows again at the 2nd line: An unhandled exception of
type 'System.NotSupportedException' occurred in System.Windows.Forms.dll
additional information: NotSupportedException
The picMainScreen is just a picturebox on the mainform...weird huh?

Jacco.
 
ehmm...
I changed
Dim gfx As Graphics = picMainScreen.CreateGraphics
to
Dim gfx As Graphics = form1.CreateGraphics

This doesn;t work. What DOES work is this:
Dim gfx As Graphics = me.CreateGraphics

Thanks for your time!
Jacco
 
Just for clarification, assuming that you are calling Me.CreateGraphics from
inside a Form instance, the CreateGraphics call is being made against the
Form object. This is supported. But calling PictureBox1.CreateGraphics is
not. This is why you were getting the exception. And assuming that "form1"
is a valid reference to an existing Form instance then
"form1.CreateGraphics" should have worked as well.
 
Back
Top