I am using method TextRenderer.MeasureText(username, new Font("Verdana", 12)).Width for validating size of username, and it shows me different values for the same username on my local machine and on server. Also in unit test it's calculating different width than in Web app on local machine (the same width as calculated on server). I think that it's because different setting on my local machine IIS, but it's puzzling me. I think that value showed on my local machine is wrong, because it's far too high (180 px) than allowed 140 pixels.
Update: When I used device context it gave the same results, different width on different machines and in unit test and web app on the same machine:
Bitmap B = new Bitmap(16, 16); // Whatever, we only need a Graphics
Graphics G = Graphics.FromImage(B);
int verdanaWidth = TextRenderer.MeasureText(G, username, new Font("Verdana", 12)).Width;
The width is different on unit test and in web app because Graphics object has different resolution:
float dpiX = G.DpiX; // 96 in unit test, 120 in web app on local machine, 96 on server
float dpiY = G.DpiY; // 96 in unit test, 120 in web app on local machine, 96 on server