我正在创建一个 Kiosk 应用程序。我有它全屏,我直接在表格上绘图:
Private Function CreateHeader(ByVal headerText As String) As Boolean
Try
Dim oGFX As Graphics = Graphics.FromHwnd(hwnd:=_oP.Handle)
Dim oRect As Rectangle = New Rectangle(x:=0, y:=0, Width:=_screenSize.X, Height:=150)
Dim oBMP As New Bitmap(GetEmbeddedResourceStream("Kiosk.logo.jpg"))
Dim oBrush As Brush = New SolidBrush(Color.FromArgb(red:=0, green:=0, blue:=153))
oGFX.FillRectangle(brush:=oBrush, rect:=oRect)
oGFX.DrawImage(image:=oBMP, _
x:=0, _
y:=0, _
width:=oBMP.Width, _
height:=oBMP.Height)
If Not String.IsNullOrEmpty(headerText) Then
Dim oFont As New Font("Impact", 48, FontStyle.Regular)
Dim g As Graphics = Me.CreateGraphics()
Dim oStringSize As SizeF = g.MeasureString(headerText, oFont)
g = Nothing
oGFX.DrawString(s:=headerText, _
font:=oFont, _
brush:=Brushes.White, _
x:=(oRect.Width - Math.Round(oStringSize.Width, 0)) / 2, _
y:=(oRect.Height - Math.Round(oStringSize.Height, 0)) / 2)
End If
Return True
Catch ex As Exception
Return False
End Try
End Function
一切都画得很好,但是当我按下 Alt 或 Tab (单独或一起,以任何顺序)时,我绘制的矩形消失了。如果我再次调用该函数,无论我按什么按钮,它都会重绘并保持不变。是否有某种我需要调用的 .NET 函数,所以我的绘图函数只需要调用一次?
谢谢。