0
중간에 텍스트가있는 diaganol 스플릿을 사용하여 노란색과 녹색의 두 가지 색상을 가진 사각형을 그리려고합니다.GDI +를 사용하여 드로잉 할 때 영역을 마스크하는 방법
문제는 노란색 위에있을 때 녹색과 검정색 위에 흰색 인 가운데에있는 텍스트를 원합니다.
여기 예 :
내가 그릴 수 있습니다 노란색, 녹색과 검은 색 또는 흰색으로 하나의 텍스트,하지만 어떻게 내가 원하는 효과를 얻을 수있는 텍스트를 마스크 할 수 있습니까?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim colour1Brush As New SolidBrush(Color.Yellow)
Dim colour2Brush As New SolidBrush(Color.Green)
Dim g As Graphics = Me.CreateGraphics
Dim rect As New Rectangle(New Point(50, 50), New Size(100, 50))
With g
'draw the background yellow
.FillRectangle(colour1Brush, rect)
'put in the black text
DrawText(g, rect, "12", Brushes.Black)
'draw the green triangle
Dim triPoints(2) As Point
triPoints(0) = New Point(rect.Left + rect.Width, rect.Top)
triPoints(1) = New Point(rect.Left + rect.Width, rect.Top + rect.Height)
triPoints(2) = New Point(rect.Left, rect.Top + rect.Height)
.FillPolygon(colour2Brush, triPoints)
'now we need white text that doesn't overwrite the existing black text
'?????? DrawText(g, rect, "12", Brushes.White)
End With
End Sub
Private Sub DrawText(ByRef g As Graphics, ByVal rect As Rectangle, ByVal text As String, ByVal brush As Brush)
Dim fnt As New Font("Segoe UI", 8)
Dim textSize As SizeF = g.MeasureString(text, fnt)
Dim x As Integer = CInt(rect.Left + ((rect.Width/2) - (textSize.Width/2)))
Dim y As Integer = CInt(rect.Height + ((rect.Height/2) - (textSize.Height/2)))
g.DrawString(text, fnt, brush, New Point(x, y))
End Sub