Graphics Arrggghhh!

  • Thread starter Thread starter T Clancey
  • Start date Start date
T

T Clancey

Hi.

I got around my previous problem by creating a bitmap references to a
graphic where I draw my string, I then set the image of the picture box to
the bitmap.

This works, although it's a little clumbsy, I now have reference to 15 of
each in code, couldn't see a way to dynamically create the objects with the
dymanically created picture boxes. Never mind, I can cope with this for the
time being.

I'm now stuck with getting the dimensions of the DrawString result.

As I'm creating the Bitmap objects before anything happens I have to give
them dimensions. I then draw my string, say, on a 500 x 500 bitmap. But, I
need to reduce the size of the bitmap or picture box to the size of the
DrawString result.

Any ideas?

Cheers,
Tull.
 
Trying to understand what you are doing. Would this be correct?

Public Class MyControl
Inherits System.Windows.Forms.Panel

' somewhere in your code
Dim gr as Graphics = CreateGraphics
Dim z as SizeF = gr.Measurestring(mytext, font)
gr.Dispose
Dim bmp as Bitmap(cint(z.Width),cint(z.Height))
gr = Graphics.FromImage(bmp)
gr.DrawString(mytext, font)
gr.Dispose
BackGroundImage = bmp
 
Back
Top