I have some code which worked fine in framework 1.1 but is giving me an ArgumentException in 2.0. The code follows:
using (Font fntDraw = new Font("Arial", 16, FontStyle.Regular))
{
Rectangle rcLayout = new Rectangle(0, 0, _cpixCell, _cpixCell);
StringFormat sfmt = new StringFormat();
sfmt.Alignment = StringAlignment.Center;
sfmt.LineAlignment = StringAlignment.Center;
g.DrawString("F", fntDraw, br, rcLayout, sfmt);
}
The DrawString call generates the exception. I can draw pretty much anything else into this Graphics object (which is attached to an internal bitmap) and I could draw the "F" in 1.1 but in 2.0 this blows up. Any ideas
Thanks!
Darrell Plank

ArgumentException in DrawString
Sachin Sinha MSFT
I think you've nailed it. Pretty obscure - not exactly writ large in the documentation and confusing when it arises but I appreciate the info.
David Mc Quillan
Does yours work with a regular Rectangle rather than a RectangleF
I was hopeful that this would fix it originally but it doesn't seem to work in my project. I wondered if there were some way the font didn't really exist on my machine (I switched machines as well as platforms when I went from 1.1 to 2.0) but the font object comes back with no complaint and I can't imagine having any problem with Arial as a font.
markp5511
g.FillRectangle(br,
new Rectangle(0, 0, _cpixCell, _cpixCell));then I get the expected solid black square.
awesj
Bitmap bmp = new Bitmap(30, 30);
using (Graphics g = Graphics.FromImage(bmp))
{
#if false
g.CompositingMode = CompositingMode.SourceCopy;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
#endif
using (Font fntDraw = new Font("Arial", 16, FontStyle.Regular))
{
g.DrawString("F", fntDraw, new SolidBrush(Color.Black), new PointF(0f, 0f));
}
}
If the stuff in the conditional is put in then we get the error in 2.0 but not in 1.1. If it's excluded then we work okay on either platform.
David Holcomb
Regular Rectangle will not work.
Marfig
http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpref/html/frlrfSystemDrawingGraphicsClassDrawStringTopic4.asp frame=true
Pravin Indurkar
RectangleF
rcLayout = new RectangleF(0, 0, 10.0f, 10.0f);and the problem persists. Sigh.
It is interesting, though, if it was possible to use a Rectangle in 1.1 but not in 2.0. I would have assumed that it was just coercing the Rectangle into a RectangleF which is a performance hit but ought to work in 2.0 if it worked in 1.1.
Strange.
Vladimir Savinov
Stubey
Kamran100
Is the exception you are getting an ArgumentNullException or just ArgumentException Is it possible for you to add the call stack for the failure
I have tried your code and cannot reproduce the problem. Can you report a bug on this adding detail steps to reproduce the issue http://lab.msdn.microsoft.com/productfeedback/Default.aspx
thanks,
sonali1754
rsb_mda