이 항목은 아직 평가되지 않았습니다.이 항목 평가

Graphics.DrawString 메서드 (String, Font, Brush, RectangleF)

지정된 사각형에 지정된 BrushFont 개체로 지정된 텍스트 문자열을 그립니다.

네임스페이스: System.Drawing
어셈블리: System.Drawing(system.drawing.dll)

public void DrawString (
	string s,
	Font font,
	Brush brush,
	RectangleF layoutRectangle
)
public void DrawString (
	String s, 
	Font font, 
	Brush brush, 
	RectangleF layoutRectangle
)
public function DrawString (
	s : String, 
	font : Font, 
	brush : Brush, 
	layoutRectangle : RectangleF
)

매개 변수

s

그릴 문자열입니다.

font

문자열의 텍스트 형식을 정의하는 Font입니다.

brush

그려지는 텍스트의 색과 질감을 결정하는 Brush입니다.

layoutRectangle

그려지는 텍스트의 위치를 지정하는 RectangleF 구조체입니다.

예외 형식 조건

ArgumentNullException

brush가 Null 참조(Visual Basic의 경우 Nothing)인 경우

- 또는 -

s가 Null 참조(Visual Basic의 경우 Nothing)인 경우

s 매개 변수에 의해 나타나는 텍스트는 layoutRectangle 매개 변수에 의해 나타나는 사각형의 내부에 그려집니다. 텍스트가 사각형에 맞지 않으면 가장 가까운 단어에서 잘립니다. 사각형 내부에 문자열을 그리는 방법을 추가로 조작하려면 StringFormat을 가져오는 DrawString 오버로드를 사용합니다.

다음 코드 예제는 Windows Forms에 적용되며, 여기에는 Paint 이벤트 처리기의 매개 변수인 PaintEventArgse가 필요합니다. 이 코드는 다음 작업을 수행합니다.

  • 그릴 텍스트 문자열을 만듭니다.

  • 글꼴을Arial(16pt)로 정의합니다.

  • 그리는 데 사용할 단색의 검정 브러시를 만듭니다.

  • 텍스트를 그릴 사각형을 만듭니다.

  • 사각형을 화면에 그립니다.

  • 글꼴, 브러시 및 대상 사각형을 사용하여 화면에 문자열을 그립니다.

public void DrawStringRectangleF(PaintEventArgs e)
{
             
    // Create string to draw.
    String drawString = "Sample Text";
             
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
             
    // Create rectangle for drawing.
    float x = 150.0F;
    float y = 150.0F;
    float width = 200.0F;
    float height = 50.0F;
    RectangleF drawRect = new RectangleF(x, y, width, height);
             
    // Draw rectangle to screen.
    Pen blackPen = new Pen(Color.Black);
    e.Graphics.DrawRectangle(blackPen, x, y, width, height);
             
    // Draw string to screen.
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect);
}

public void DrawStringRectangleF(PaintEventArgs e) 
{
    // Create string to draw.
    String drawString = "Sample Text";

    // Create font and brush.
    Font drawFont =  new Font("Arial", 16);
    SolidBrush drawBrush =  new SolidBrush(Color.get_Black());

    // Create rectangle for drawing.
    float x = 150;
    float y = 150;
    float width = 200;
    float height = 50;
    RectangleF drawRect =  new RectangleF(x, y, width, height);

    // Draw rectangle to screen.
    Pen blackPen =  new Pen(Color.get_Black());
    e.get_Graphics().DrawRectangle(blackPen, x, y, width, height);

    // Draw string to screen.
    e.get_Graphics().DrawString(drawString, drawFont, drawBrush, drawRect);
} //DrawStringRectangleF

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원
이 정보가 도움이 되었습니까?
(1500자 남음)
커뮤니티 콘텐츠 추가