I have the following method in C#:
private string adjustColumnValueLength(String value, int maxLength, PaintEventArgs e)
{
// Set up our string font
System.Drawing.Font printFontText = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Regular);
SizeF stringSize = new SizeF();
string newValue = value;
// Loop until the string fits the size we need
for (int x = value.Length; x >= 0; x--)
{
// Measure the string
newValue = value.Substring(0, x);
stringSize = e.Graphics.MeasureString(newValue, printFontText);
Size roundedSize = Size.Round(stringSize);
if (Int32.Parse(roundedSize.ToString()) <= maxLength)
{
return newValue;
}
}
return newValue;
}
I am calling this from within another method to get the length of a string to match the width in pixels I have to display it, however I have NO idea how I am supposed to pass in the PaintEventArgs. I've tried using System.Windows.Forms.PaintEventArgs but that does not work.
How can this be accomplished?
Aucun commentaire:
Enregistrer un commentaire