你需要两个bitmaps
和一个picturebox
才能工作。第一个是png
图像,第二个是picturebox
图像:
Private pngImage, picBoxImage As Image
在表单加载事件中初始化两个图像:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
pngImage = Image.FromFile(FOLDER_PATH & "\completed.png") //load it once
picBoxImage = CType(pngImage.Clone, Image)
PictureBox1.Size = New Size(CInt(463 / 2), CInt(242 / 2))
PictureBox1.Parent = GroupBox6
PictureBox1.Image = picBoxImage
PictureBox1.Visible = False //you dont want it at the beggining
End Sub
显示图片框的子:
Private Sub ShowCompletedMessage()
Dim screenLocation As Point
Dim gr As Graphics
//you can pass these values as parameters in the sub if you want to make the code more generic
Dim x As Integer = CInt(((GroupBox6.Width / 2) - (463 / 4)))
Dim y As Integer = 10
Dim width As Integer = CInt(463 / 2)
Dim height As Integer = CInt(242 / 2)
//Ensure that picturebox is not visible. If it is you don't need to take a screenshot
If PictureBox1.Visible = True Then
Return
End If
gr = Graphics.FromImage(picBoxImage)
//you need to transform the coordinates to screen ones
screenLocation = GroupBox6.PointToScreen(New Point(x, y))
//draw the portion of the screen to your bitmap
gr.CopyFromScreen(screenLocation.X, screenLocation.Y, 0, 0, New Size(width, height), CopyPixelOperation.SourceCopy)
//draw the png image on top
gr.DrawImage(pngImage, 0, 0, width, height)
PictureBox1.Location = New Point(x, y)
PictureBox1.BringToFront()
PictureBox1.Visible = True
gr.Dispose()
gr = Nothing
Return
End Sub
每次你想显示消息时调用上面的 sub。您决定何时何地。picturebox
如果你不再需要它,你需要隐藏
PictureBox1.Visible = False