VB.NET绘制在矩形e.Graphics之上

时间:2015-03-24 17:08:38

标签: vb.net graphics png

我想使用e.Graphics绘制到我的表单。所以我绘制了一组矩形(对于我正在制作的游戏的棋牌),现在我想在已绘制(和工作)的矩形上绘制棋子。国际象棋棋子是透明的png保存在我的Resources文件夹中。我没有问题正常绘制它们,但每当我想在瓷砖上绘制它们时,只有瓷砖是可见的 - 无论哪一行代码首先出现。如何在瓷砖顶部添加碎片,以便瓷砖位于下方?

这是有问题的代码:

If Not alreadydrawn Then
    Dim g As Graphics = Graphics.FromImage(screenbuffer)
    Checked = False
    For y = 1 To 8
        For x = 1 To 8
            If Checked Then g.FillRectangle(Brushes.LightGray, (x * 85) - 40, (y * 85) - 40, 85, 85)
            If Not Checked Then g.FillRectangle(Brushes.Black, (x * 85) - 40, (y * 85) - 40, 85, 85)
            Checked = Not Checked
        Next
        Checked = Not Checked
    Next
    e.Graphics.DrawImage(My.Resources.Bishop_White, New Rectangle(New Point(50, 50), New Size(64, 64)))
    alreadydrawn = True
End If
e.Graphics.DrawImageUnscaledAndClipped(screenbuffer, New Rectangle(New Point(0, 0), New Size(795, 805)))

1 个答案:

答案 0 :(得分:0)

这是我提出的解决方案:

checked = False
For y = 1 To 8
    For x = 1 To 8
        If clickedsquare(0) = x - 1 And clickedsquare(1) = y - 1 And Not boardlayout(y - 1, x - 1) = 0 And clickmode = "options" Then
            t.FillRectangle(New SolidBrush(Color.FromArgb(225, 212, 128)), x * 75, y * 75, 75, 75)
        Else
            If checked Then t.FillRectangle(New SolidBrush(Color.FromArgb(64, 64, 64)), x * 75, y * 75, 75, 75)
            If Not checked Then t.FillRectangle(New SolidBrush(Color.FromArgb(224, 224, 224)), x * 75, y * 75, 75, 75)
        End If
        checked = Not checked
    Next
    checked = Not checked
Next

...

然后:

tiles.Image = tilebuffer
pieces.Image = piecebuffer
BackgroundImage = tiles.Image
pieces.BackColor = Color.Transparent
alreadydrawn = True