你需要兩個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
每次你想顯示消息調用上面的子。你決定從何時何地。你需要隱藏picturebox
,如果你不需要它了
PictureBox1.Visible = False
你要顯示的圖像的疊加,當用戶完成一個過程,隱藏背後的控制?我認爲當狀態爲「已取消」時,使用顯示的PictureBox控件而不是Groupbox會更容易,而不是在groupbox上繪製圖像。 – Markus
@Markus如果我使用圖片框,它不透明,這就是爲什麼我在控件上繪製圖像,以保持它。但在我的情況下,txtbox和標籤覆蓋圖像。我只是想繪製它,也許把它發送到羣組框中的gropbox和其他控件的前面 – Muj
有兩種解決方案,我可以想到。 1.創建一個分層窗口並將其顯示在控件的頂部2.以圖片將出現的部分的截圖並將其繪製在picbox上,然後繪製png圖像 –