以下代码不起作用:
Private Sub panelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles panelButton.Click
Dim myBrush As Brush
myBrush = New SolidBrush(Color.Yellow)
fBitmap = New Bitmap(picturePanel.Width, picturePanel.Height)
Dim gg As Graphics = Graphics.FromImage(fBitmap)
gg.Clear(Color.White)
'<<<<<my attempt<<<<<<
Dim rec As Rectangle
rec = New Rectangle(picturePanel.Location.X, picturePanel.Location.Y, picturePanel.Width, picturePanel.Height)
gg.FillRectangle(myBrush, rec)
'<<<<<<<<<<<<<<<<<<<<<
'gg.FillRectangle(myBrush, gg.ClipBounds) '<<actual answer
gg.Dispose()
picturePanel.Refresh()
End Sub
在面板的重绘处理程序中,我得到了这个:
Private Sub picturePanel_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles picturePanel.Paint
If fBitmap IsNot Nothing Then
e.Graphics.DrawImage(fBitmap, 0, 0)
End If
End Sub
我已经包含了推荐的代码(标记为actual answer
),但是为什么标记的部分没有my attempt
将面板变为黄色?- 可以对其进行调整以使面板变黄吗?