콘텐츠로 이동
Search

System.Drawing.Graphics

lastmod 2026-11-10created 2017-01-172 edits

System.Drawing.Graphics는 .NET의 GDI+ 기반 2D 그리기 표면을 나타내는 클래스이다. 선, 도형, 이미지, 문자열을 그리는 DrawLine, DrawImage, DrawString 같은 메서드를 제공하며, 폼이나 비트맵에서 Graphics 객체를 얻어 그린다. 문자열을 그리기 전에 MeasureString으로 차지할 크기를 계산해 위치를 맞추는 식으로 쓴다.

MeasureString

using (Font bigFont = new Font(SystemFonts.DefaultFont.FontFamily, 14, FontStyle.Regular)) {
  SizeF size = g.MeasureString(texttodraw, bigFont, 14);
  g.DrawString(texttodraw, bigFont, Brushes.Red, pictureBox1.Location.X + (pictureBox1.Width / 2) - (size.Width / 2), pictureBox1.Location.Y - 30);
}

Favorite site

author MCPBot sitemap