1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
Option Explicit On
Option Strict On
Public Class Form5
Private bBackgroundBuffer As Bitmap
Private WithEvents t As New Timer
Sub New()
InitializeComponent()
refreshBackGround()
t.Interval = 100
t.Start()
End Sub
Dim intNumberOfTick As Integer
Private Sub t_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles t.Tick
intNumberOfTick += 1
Me.Invalidate()
End Sub
Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
MyBase.OnSizeChanged(e)
refreshBackGround()
End Sub
Dim intNumberOfRefresh As Integer
Private Sub refreshBackGround()
intNumberOfRefresh += 1
bBackgroundBuffer = New Bitmap(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
Dim gd As Graphics = Graphics.FromImage(bBackgroundBuffer)
Dim b As New _
System.Drawing.Drawing2D.LinearGradientBrush(Me.ClientRectangle, _
Color.Black, _
Color.Black, _
35, False)
Dim cb As New System.Drawing.Drawing2D.ColorBlend()
cb.Colors = _
New Color() {Color.Red, _
Color.Orange, _
Color.Aqua, _
Color.LightBlue, _
Color.Blue}
cb.Positions = _
New Single() {0, 0.25, 0.5, 0.75, 1}
b.InterpolationColors = cb
gd.FillRectangle(b, Me.ClientRectangle)
gd.Dispose()
End Sub
Dim fFont As Font = New Font("DS-Digital", 20, FontStyle.Italic)
Dim bBrush As Brush = New SolidBrush(Color.White)
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As IntPtr) As Boolean
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim ip As IntPtr = bBackgroundBuffer.GetHbitmap
Dim ibufferImage As Bitmap = Bitmap.FromHbitmap(ip)
Dim gd As Graphics = Graphics.FromImage(ibufferImage)
gd.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
gd.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
gd.DrawString(Now.ToString, fFont, bBrush, New Point(0, 0))
gd.DrawString("Refresh : " & intNumberOfRefresh.ToString, fFont, bBrush, New Point(0, 50))
gd.DrawString("Tick : " & intNumberOfTick.ToString, fFont, bBrush, New Point(0, 100))
e.Graphics.DrawImage(ibufferImage, 0, 0)
DeleteObject(ip)
gd.Dispose()
ibufferImage.Dispose()
End Sub
Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
End Sub
End Class |
Partager