문제

I am writing info entered on a web form into a tiff file. My issue is where the comment box comes into play for the web form. The comment box is multi-line and when writing it on to the tiff file, some of the information entered into the comment box falls out of the tiff image.

The code for how I am trying to write it to the tiff file:-

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000); //Creates Bitmap
Graphics g = Graphics.FromImage(bitmap);
g.DrawString("Comment: " + CommentBox.Text, outputFont, Brushes.Black, new PointF(0, 700)); // Writing the text from the comment box on to the Tiff file.

so what that means to me is, if I am writing a multi line comment as:-

"Hello Testing.

Hello Testing again and again and again and again and again and again and again.

Hello Testing again and again and again and again and again and again and again. Hello Testing again and again and again and again and again and again and again."

My tiff-file captures line elements only upto the 1000 width, the elements beyond that width do not automatically get generated in a new line.

Can anyone help me with this? ideas?

도움이 되었습니까?

해결책

Try something like this - you can use the overload of DrawString that takes a containing rectangle, and the text should wrap within that:

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000); //Creates Bitmap
using(Graphics g = Graphics.FromImage(bitmap))
{
   RectangleF rect = new RectangleF(new PointF(0, 700), new SizeF(200,200)); // adjust these accordingly for your bounding rect
   StringFormat drawFormat = new StringFormat();
   drawFormat.Alignment = StringAlignment.Near;
   g.DrawString("Comment: " + CommentBox.Text, outputFont, Brushes.Black, rect, drawFormat); // Writing the text from the comment box on to the Tiff file.
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top