473,811 Members | 3,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Measurestring?

I want to use Measurestring in a Class.

In a form I write cInt(Me.CreateG raphics.Measure string("Text", mFont).Width)

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

Marc
Nov 20 '05 #1
5 6825
Hello,

"Marc" <Marc.VanSchand evijl@_nospam_. c-luma.com> schrieb:
I want to use Measurestring in a Class.

In a form I write cInt(Me.CreateG raphics.Measure string("Text", mFont).Width)
What do I write in a class (I dont't have the Me.CreateGraphi cs there...)


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

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 20 '05 #2
"Marc" <Marc.VanSchand evijl@_nospam_. c-luma.com> schrieb
I want to use Measurestring in a Class.

In a form I write cInt(Me.CreateG raphics.Measure string("Text",
mFont).Width)

What do I write in a class (I dont't have the Me.CreateGraphi cs
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.CreateG raphics.Measure string("Text", mFont).Width)

you should write

dim g as graphics
g= Me.CreateGraphi cs
cInt(g.Measures tring("Text", mFont).Width)
g.dispose

--
Armin

Nov 20 '05 #3
As I already stated, there is no Me-object, since there is no form...

Marc

"Armin Zingler" <az*******@free net.de> schreef in bericht
news:eL******** ******@TK2MSFTN GP11.phx.gbl...
"Marc" <Marc.VanSchand evijl@_nospam_. c-luma.com> schrieb
I want to use Measurestring in a Class.

In a form I write cInt(Me.CreateG raphics.Measure string("Text",
mFont).Width)

What do I write in a class (I dont't have the Me.CreateGraphi cs
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.CreateG raphics.Measure string("Text", mFont).Width)

you should write

dim g as graphics
g= Me.CreateGraphi cs
cInt(g.Measures tring("Text", mFont).Width)
g.dispose

--
Armin

Nov 20 '05 #4
Hello,

"Marc" <Marc.VanSchand evijl@_nospam_. c-luma.com> schrieb:
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
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 20 '05 #5
Hello,

"Marc" <Marc.VanSchand evijl@_nospam_. c-luma.com> schrieb:
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
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2540
by: Alien | last post by:
Why does this code Console.WriteLine(g.MeasureString("a", new Font("Lucida Console", 11f)).Width); Console.WriteLine(g.MeasureString("aa", new Font("Lucida Console", 11f)).Width); produce this output: 13.9911
1
7357
by: Jesse Wade | last post by:
I'm trying to create a function that will pad a string with spaces so that the resulting string is a specific width (in this case 50points). As expected, the following code when passed an empty string will add a space and I see the width increase. All subsequent times through the loop, the width does not increase though the spaces are being added to "value"... Please help! private string AdjustSpace(string text){ Form f = new Form();...
1
5046
by: Yaron | last post by:
Hi, I made a procedure which receives a Graphics parameter, and with that Graphics parameter, performs various things. The area of confusion here is that when I pass the procedure a Graphics object created by a Panel, and use the MeasureString() method, I get a different width than when I pass up the procedure a Graphics object created by a PrintDocument. The procedure is exactly the same, independent of which object called it, so why...
2
3609
by: Stuart Norris | last post by:
Dear Group, I have a question about the result from ‘graphics.MeasureString' when using a mono-spaced font. Firstly I assume that Courier New font is mono-spaced, ie each character takes up the same space when drawn on the screen. I am working on a program that requires displaying data in fixed width font. I assumed that with ‘graphics.MeasureString' I could calculate the width of the string when drawn in a specified font.
0
2228
by: keith | last post by:
I did a test typing characters until fill out whole textbox (single line). Then I chcked width of this string in paint event e.Graphics.MeasureString(textBox1.Text,textBox1.Font).Width e.g. the textBox1.Width=268 I typed in 35 'A' with default Font. width retured from MeasureString function is 252
0
1373
by: Meetali Goel | last post by:
Hi all, I can't determine why I keep getting "NotSupportedException" when g.MeasureString() is called in the following code (.NET CE). I have spent several hours but I cant seem to find the solution. I would really appreciate it if someone could look at the code below. Label l = new Label();
7
6416
by: teo | last post by:
Hallo, I'd like to retrieve the pixel length of a string. ------------------------ I decided to use MeasureString, but I have a problem with the graphic "instance" of it. I'm in a Sub and
2
2071
by: teo | last post by:
I have to measure the length of a string in a Label, to set the adequate Label width (because not all browsers support the auto-size Label property). I decide to use the 'MeasureString' method. It works on a Win Form, but it doesn't work on a Web Form. I see the usual blue zig-zag underline
6
10568
by: Rainer Queck | last post by:
Hello NG, I am trying to adjust the column width of a DataGridView to the Text in its column header. To do this I am using the Graphics.MeasureString method. Unfortunatly I alway get a too short string width. What is it I am doing wrong? Here the code I am using: private void MinimizeDgvColumns(DataGridView dgv)
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.