I am creating a Kiosk application. I have it full screen and I am drawing directly on the form:
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
Everything draws fine, but the second I press Alt or Tab (individually or together, in any order) the rectangle I drew disappears. If I call the function again, it redraws and stays no matter what button I press. Is there some sort of .NET function that I need to call so my drawing function only needs to be called once?
Thanks.