Reputation: 1269
Resolved:
With 'Optimize Code' disabled in the projects settings, everything is working now
I have the following code in three projects...a newly created blank one, and two actual ones. In the newly created blank one and one actual project, it works. But in the third project, it doesn't.
System.Drawing.Bitmap m = new System.Drawing.Bitmap((int)(this.NomLabel.Size.Width * pcntDbl), (int)(this.NomLabel.Size.Height * pcntDbl));
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(m);
System.Drawing.Font stringFont = new System.Drawing.Font("Arial", (float)(this.NomLabel.Font.Size * pcntDbl), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
float foo = g.MeasureString(this.NomLabel.Text, stringFont).Width;
When I say doesn't, the error is 'foo does not exist in the current context' is the error when trying to access foo. I put everything in a try/catch block, and nothing gets thrown. I can't use foo (obviously, but I need to) and am not sure what's going on here. The same code works in a newly created blank project. Oddly enough, changing the last line to
string foo = g.MeasureString(this.NomLabel.Text, stringFont).Width.ToString();
successfully sends the float to a string, but I can't convert it back to a double or int, it does the same thing. And by same thing, I mean it looks like it executes the line of code as I step through it, but doesn't do anything. Anyone have any idea what's going on or what I could try? Thanks!
By the way, the project is way too large to put it in a new project for those wondering.
EDIT: TextRenderer.MeasureString does the same thing. Looks like it executes but nothing is returned when trying to save the width to an int variable.
EDIT 2: I just added a
int temp = (int)foo;
and while I can now read the foo variable, I can't read the temp variable.
EDIT 3: The function that this is in is called by the constructor. I made it so that this function is called explicitly rather than in the constructor, and it still didn't work. I also have SuspendLayout() for NomLabel above this chunk of code and moved that to below this code and still, that didn't work.
When executing the foo line and moving to the temp line, I can see foo variable and its value. But once I get to the temp line and try and execute that, it jumps to the next line of code and I can't see anything. Again, all of this works fine in the brand new project so I don't understand what might be the issue with this one.
EDIT 4: I copied the existing (broken) csproj file to the blank project, removed the old files and references from it, added my blank (new) files and its not working. I think its something with the csproj file as its the only thing that changed with the blank project.
Upvotes: 0
Views: 474
Reputation: 1269
With 'Optimize Code' disabled in the projects settings, everything is working now.
Upvotes: 1