CodeA :Drawstring이 서로 겹치고 있습니까?
Image imageChipsetName = new System.Drawing.Bitmap(photoWidth, photoHeight);
StringFormat strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
Graphics graphics = Graphics.FromImage(imageChipsetName);
graphics.DrawString(stringA + "\n",
new Font("Tahoma", 14, FontStyle.Underline), Brushes.Black,
new RectangleF(0, 0, photoWidth, photoHeight), strFormat);
graphics.DrawString(stringB,
new Font("Tahoma", 14), Brushes.Black,
new RectangleF(0, 0, photoWidth, photoHeight), strFormat);
CodeB :
Image imageChipsetName = new System.Drawing.Bitmap(photoWidth, photoHeight);
StringFormat strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
Graphics graphics = Graphics.FromImage(imageChipsetName);
graphics.DrawString(stringA + "\n"+stringB,
new Font("Tahoma", 14, FontStyle.Underline), Brushes.Black,
new RectangleF(0, 0, photoWidth, photoHeight), strFormat);
나는 상자 내에서 두 문자열을 그릴 필요가있다. 밑줄 스타일이있는 StringA StringB는 그렇지 않습니다.
코드 B는 내가 원하는 것을 거의 달성하지만 stringA
과 stringB
은 같은 스타일을 공유합니다. 그래서 CodeA로 테스트했는데, 그 프로그램은 두 문자열이 서로 겹치는 것입니다. 알 수 있어요
'DrawString()'은 한 번의 호출로 줄 바꿈 만 처리합니다. 그것은 하나의 호출에서 다음 호출로 상태를 가지지 않습니다. 따라서 여러 줄로 다른 스타일로 그릴 필요가 있다면'DrawString()'을 호출 할 때마다 문자열을 올바르게 그려야 할 위치를 지정해야합니다. 관련 세부 정보 및 추가 정보 링크는 중복 표시된 부분을 참조하십시오. –