J
Jesse Wade
I'm trying to create a function that will pad a string with spaces so
that the resulting string is a specific width (in this case 50points).
As expected, the following code when passed an empty string will add
a space and I see the width increase. All subsequent times through
the loop, the width does not increase though the spaces are being
added to "value"... Please help!
private string AdjustSpace(string text){
Form f = new Form();
Graphics g = f.CreateGraphics();
g.PageUnit = GraphicsUnit.Point;
float width;
SizeF size;
do{
size = g.MeasureString(text, new
Font(System.Drawing.FontFamily.GenericSerif,10));
width = size.Width;
text = " " + text;
}
while(width<50);
return text;
}
that the resulting string is a specific width (in this case 50points).
As expected, the following code when passed an empty string will add
a space and I see the width increase. All subsequent times through
the loop, the width does not increase though the spaces are being
added to "value"... Please help!
private string AdjustSpace(string text){
Form f = new Form();
Graphics g = f.CreateGraphics();
g.PageUnit = GraphicsUnit.Point;
float width;
SizeF size;
do{
size = g.MeasureString(text, new
Font(System.Drawing.FontFamily.GenericSerif,10));
width = size.Width;
text = " " + text;
}
while(width<50);
return text;
}