|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Graphics.MeasureStringhttp://msdn2.microsoft.com/en-us/library/6xe5hazb.aspx Dim instance As Graphics Dim text As String 'Dim strfont As Font Dim returnValue As SizeF text = "asdas asd asd asd" Dim strfont As New Font("Arial", 16) returnValue = instance.MeasureString(text, strfont) and it still does not work! I get an error saying Oject reference is not set to an intance of an object. I have tried all kinds of combinations, but it still will not work. In the documentation i.e. dynamic help the implementation seems to be different. Can anyone tell me how to implement this? Thanx, Hi Anil,
The variable "instance" is declared but not assigned, and you get an NullReferenceException. If you are inside a Paint event handler, set e.Graphics to it. Otherwise, you could use Control.CreateGraphics. Using instance As Graphics = someControl.CreateGraphics() ' code here End Using Thi http://thith.blogspot.com/ Anil Gupte wrote: Show quoteHide quote > I copied the following almost directly from > http://msdn2.microsoft.com/en-us/library/6xe5hazb.aspx > > Dim instance As Graphics > > Dim text As String > > 'Dim strfont As Font > > Dim returnValue As SizeF > > text = "asdas asd asd asd" > > Dim strfont As New Font("Arial", 16) > > returnValue = instance.MeasureString(text, strfont) > > > and it still does not work! I get an error saying Oject reference is not > set to an intance of an object. I have tried all kinds of combinations, but > it still will not work. In the documentation i.e. dynamic help the > implementation seems to be different. > > Can anyone tell me how to implement this? > > Thanx, > -- > Anil Gupte > www.keeninc.net > www.icinema.com Yes, only 4 minutes. :-) But thanx to both of you. I now understand how to
do it but seems exceptionally convoluted. I had inf act tried the New keyword and it still had not worked. A class that you can't really use? How like Microsoft.... Anyway thanx again to both. Show quoteHide quote "Norman Chong" <normanch***@freenet.de> wrote in message news:1161866581.647399.84180@e3g2000cwe.googlegroups.com... > > Truong Hong Thi schrieb: > > Seems I was a few minutes too late... :-) > Anil Gupte schrieb:
> Hi Anil,> and it still does not work! I get an error saying Oject reference is not > set to an intance of an object. I have tried all kinds of combinations, but > it still will not work. In the documentation i.e. dynamic help the > implementation seems to be different. The error is correct :-) When you just write "Dim instance As Graphics" you don't have an instance of this class. When you debug it you see that the value of 'instance' is nothing. Normally it must be "Dim instance as new Graphics" but because Graphics has no constructors, this won't work too. So you have to get the graphics object from another object which can create a graphics object for you (e.g. a Control) Example ( Get Graphics object from a textbox) : Dim myGraphics as Graphics myGraphics = TextBox1.createGraphics()
vb, vb.net, & vba
Graphics, but keeping size down convert text to decimal Zip SharpZipLib examples for VB submenuitems not opening Convert String To dot Net Form Load Code Trapping System.NullReferenceException on start-up "ieframe.dll failed to register" Attributes question is this dataset table select correct" |
|||||||||||||||||||||||