Measurestring?

  • Thread starter Thread starter Marc
  • Start date Start date
M

Marc

I want to use Measurestring in a Class.

In a form I write cInt(Me.CreateGraphics.Measurestring("Text", mFont).Width)

What do I write in a class (I dont't have the Me.CreateGraphics there...)

Marc
 
Marc said:
I want to use Measurestring in a Class.

In a form I write cInt(Me.CreateGraphics.Measurestring("Text",
mFont).Width)

What do I write in a class (I dont't have the Me.CreateGraphics
there...)

The result of MeasureString depends on the control (or printer) you want to
display the text on. So, where do you want to display it? On solution is to
pass a graphics object to the class.


BTW, you should dispose the graphics object after usage:

Instead of

cInt(Me.CreateGraphics.Measurestring("Text", mFont).Width)

you should write

dim g as graphics
g= Me.CreateGraphics
cInt(g.Measurestring("Text", mFont).Width)
g.dispose
 
Hello,

Marc said:
I want to use Measurestring in a Class.

In a form I write cInt(Me.CreateGraphics.Measurestring("Text", mFont).Width)

What do I write in a class (I dont't have the Me.CreateGraphics there...)

You need a referece to a Graphics object or an object you can create a
Graphics object from.

Regards,
Herfried K. Wagner
 
Hello,

Marc said:
Yes, but how do I do that?

There are different ways to pass something to a class instance.

One way is to create a "public" property in the class and set this property
before calling the method:

\\\
Public Class Foo
Private m_MyGraphics As Graphics

Public Property MyGraphics() As Graphics
Get
Return m_MyGraphics
End Get
Set(ByVal Value As Graphics)
m_MyGraphics = Value
End Set
End Property
 
Hello,

Marc said:
As I already stated, there is no Me-object, since there is no form...

Where do you want to measure the string? On a form, a control, an image,
the printer, ...?

Regards,
Herfried K. Wagner
 
Back
Top