我在visual basic中创建了一组需要着色的形状:
Public Class Form1
Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
Dim formSurface As Graphics = Me.CreateGraphics 'creates surface
Dim world As New Pen(Color.Black, 3)
formSurface.DrawRectangle(world, 250, 50, 300, 300) 'world
Dim roof As New Pen(Color.Black, 3)
Dim roof1 As New Point(325, 200)
Dim roof2 As New Point(475, 200)
Dim roof3 As New Point(400, 100)
Dim roof4 As New Point(400, 100)
Dim curvePoints As Point() = {roof1, roof2, roof3, roof4}
formSurface.DrawPolygon(roof, curvePoints) 'triangle roof
Dim body As New Pen(Color.Black, 3)
formSurface.DrawRectangle(body, 325, 200, 150, 150) 'square body
Dim sun As New Pen(Color.Black, 3)
formSurface.DrawEllipse(sun, 450, 75, 50, 50) 'sun
Dim door As New Pen(Color.Black, 3)
formSurface.DrawRectangle(door, 387, 300, 25, 50) 'door
End Sub
结束班
一切都很完美;形状都是在我希望它们生成的地方生成的。 (我正在试图画一个房子)但是,我该如何着色它们呢?另外,如果我这样做,颜色是否重叠(我希望发生这种情况)?
我应该使用像image.fill
这样的功能吗?我知道这不对,但我正在寻找类似的东西。
谢谢!
答案 0 :(得分:1)
您想使用formSurface.FillPolygon,FillRectangle和FillEllipse命令。您仍然可以使用“绘制”命令创建颜色与填充颜色不同的轮廓。
“填充”命令需要画笔而不是笔。 (钢笔绘制线条,刷子填充空间。)最简单的刷子类型就像“Brushes.AliceBlue”。