I have a project in VB6 that I need to convert to C#, this project uses the TextWidth Method and I replaced it with TextRenderer.MeasureText Method in C# but I got different results for the same strings with the same fonts even after i converted the pixels to twips, does anyone know how to fix this?
my code in VB6:
Private Sub Form_Load()
MsgBox Me.TextWidth("XX")
End Sub
the output: 210
my code in C#:
public int ConvertPixelsToTwips(Graphics source, int pixel)
{
return (int)((double)pixel / ((1.0 / 1440.0) * source.DpiX));
}
private void Form1_Load(object sender, EventArgs e)
{
int pixel = TextRenderer.MeasureText("XX",this.Font).Width;
int twips;
Graphics g = CreateGraphics();
twips = ConvertPixelsToTwips(g, pixel);
MessageBox.Show("in twips: " + Convert.ToString(twips) + " in pixel: " + pixel);
}
the output: in twips: 315 in pixel: 21