vb 2015 GDI +位图放置

时间:2016-01-06 23:36:28

标签: vb.net bitmap panel gdi+

我试图在stackoverflow上专门找到答案,或者在互联网上找到答案。

我在vb 2015 Windows Forms项目中有一个表单。

在那张表格上,我放置了六个控件:四个文本框,一个面板和一个按钮。

当我点击按钮时,它会生成一个位图,如下所示:

 Private Sub btnSetLeft_Click(sender As Object, e As EventArgs) Handles btnSetLeft.Click
    Dim R As Integer = CInt(txtRedLeft.Text)
    Dim G As Integer = CInt(txtGreenLeft.Text)
    Dim B As Integer = CInt(txtBlueLeft.Text)
    Dim A As Integer = CInt(txtAlphaLeft.Text)
    gcL = Color.FromArgb(A, R, G, B)
    Using bm As Bitmap = New Bitmap(9, 9)
        Using gBM As Graphics = Graphics.FromImage(bm)
            Using br As SolidBrush = New SolidBrush(gcL)
                gBM.FillRectangle(br, New Rectangle(0, 0, 8, 8))
            End Using
        End Using
    End Using
 End Sub

但是,在构建位图之后,我希望按钮将位图放在面板上,然后重新绘制面板,从而显示新的位图。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

这并不太难(我简化了你的例子):

Dim gcL As Color = Color.Blue
Using bm As New Bitmap(9, 9)
    Using gBM As Graphics = Graphics.FromImage(bm)
        Using br As New SolidBrush(gcL)
            gBM.FillRectangle(br, New Rectangle(0, 0, 8, 8))
        End Using
    End Using
    panel1.BackgroundImage = bm
    panel1.BackgroundImageLayout = ImageLayout.Tile
    panel1.Update()
End Using