PROGRAMMING WORKSHOP

Skip Navigation Links. Skip Navigation Links.

.Net FrameWork,VB.Net | System.Drawing.Graphics

DrawString,ResetTransform,TranslateTransform, RotateTransForm

문자를 쓰는 것은 TextBox나 Label이나 Font개체를
받아주는 개체에만 쓸수 있다
그림을 받아주는 개체에는 그림으로 문자를 표현하면 된다
예를 들어..
PictureBox는 Image화일만 받아주는 개체이다
이곳에 문자를 작성하고 싶다면..
그림으로 표현하는 개체는 모두 Graphics개체..
그래서 Graphics개체를 만들기 위하여


Bitmap개체를 만들고
Dim myImage As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Bitmap개체의 FromImage메소드로 Graphics개체를 만들고
Dim myGraphic As Graphics = Graphics.FromImage(myImage)
Graphics개체의 DrawString 메소드로 문자를 표현하면
Bitmap개체에 문자가 표현되게 되고..
myGraphic.DrawString("Excel Is Fun And Useful!!!", New Font("맑은 고딕", 15), Brushes.Black, New Point(10, 10))
이 Bitmap개체를 PictureBox개체의 Image속성에 전달하면 된다
PictureBox1.Image = myImage

위의 코드로 아래와 같이 PictureBox콘트롤에 Image로
문장이 그려졌다



그런데, 매개변수중에 Point개체가 있는데, 이것의 족보는
System.Drawing.PointF 라고 되어있다



RectangleF, PointF등과 같이
개체명뒤에 F가 붙는 것은..
Rectangle, Point 은 크기나 위치가 정수(Integer)값이다
F가 붙는 것은 Floating값, 즉 소수점이하값이 표현되는 Single타입의 값이다
그러니 F가 붙는 것은 좀더 자세히,정확한 위치와 크기를 표현할수 있을 것이다

아래와 같이 문자를 작성하면서 회전이 되거나, 위치를 이동하게 하고 싶다



문자나 도형을 그리는 위치를 이동시키기 위하여 TranslateTransform 메소드
문자나 도형을 회전시키기 위한 이동을 위하여 RotateTransform 메소드
등을 사용한다..
이것을 왜 사용하는지, 쌤플을 만들어 놓았으니,실행시켜 보시면서 감각을 키우시면 된다



''순수하게 DrawingString 메소드만 사용한경우
For iX As Integer = 0 To 100 Step 10
	myGraphic.DrawString(TEXT_TO_SHOW, New Font("맑은 고딕", 12), Brushes.Black, New Point(iX, iX))
Next

''TranslateTransform 메소드를 DrawString메소드 전에 사용한 경우
For iX As Integer = 0 To 100 Step 10
	myGraphic.TranslateTransform(iX, iX)
	myGraphic.DrawString(TEXT_TO_SHOW, New Font("맑은 고딕", 12), Brushes.Black, New Point(iX, iX))
Next

''ResetTransform메소드, 이메소드의 역할이 이것이구나!!
For iX As Integer = 0 To 100 Step 10
	myGraphic.ResetTransform()
	myGraphic.TranslateTransform(iX, iX)
	myGraphic.DrawString(TEXT_TO_SHOW, New Font("맑은 고딕", 12), Brushes.Black, New Point(iX, iX))
Next

''RotateTransform 메소드를 사용한경우
For iX As Integer = 0 To 100 Step 10
	myGraphic.RotateTransform(iX)
	myGraphic.DrawString(TEXT_TO_SHOW, New Font("맑은 고딕", 12), Brushes.Black, New Point(iX, iX))
Next

''ResetTransform, TranslateTransform을 사용하면, 다시 한번, 
아하 ResetTransform 의 역할이 이것이구자!! 다시 확인
For iX As Integer = 0 To 100 Step 10
	myGraphic.ResetTransform() '' 당초의 메트릭스위치를 유지..
	myGraphic.TranslateTransform(250, 50) '' 수직,수평방향으로 이동
	myGraphic.RotateTransform(iX) '' iX각도만큼 회전이동
	myGraphic.DrawString(TEXT_TO_SHOW, New Font("맑은 고딕", 12), Brushes.Black, New Point(iX, iX))
Next
***[LOG-IN]***