1 ' =====================================================================
5 ' ---------------------------------------------------------------------
6 ' Copyright (C) Microsoft Corporation. All rights reserved.
8 ' This source code is intended only as a supplement to Microsoft
9 ' Development Tools and/or on-line documentation. See these other
10 ' materials for detailed information regarding Microsoft code samples.
12 ' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
13 ' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 ' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
16 ' =====================================================================
18 Imports System
.Threading
20 Namespace Microsoft
.Samples
.CompactFramework
22 Public Class BubbleForm
23 Inherits System
.Windows
.Forms
.Form
25 Private Const MaxBubbles
As Integer = 20
27 Private bubbles(MaxBubbles
) As Bubble
28 Private backgroundBrush
As Brush
= New SolidBrush(Color
.SlateBlue
)
29 Private backgroundPen
As New Pen(Color
.SlateBlue
)
30 Private offscreenBitmap
As Bitmap
31 Private offscreenGraphics
As Graphics
32 Private thread
As Thread
33 Private isRunning
As Boolean
34 Private realGraphics
As Graphics
35 Private cachedClientSize
As Size
37 #Region
" Windows Form Designer generated code "
43 'This call is required by the Windows Form Designer.
46 'Additional initialization
48 For bubble
= 0 To MaxBubbles
- 1
49 Me.bubbles(bubble
) = New Bubble()
50 Me.bubbles(bubble
).Init(ClientSize
)
53 Me.offscreenBitmap
= New Bitmap(ClientSize
.Width
, ClientSize
.Height
)
54 Me.offscreenGraphics
= Graphics
.FromImage(Me.offscreenBitmap
)
55 Me.offscreenGraphics
.FillRectangle(Me.backgroundBrush
, 0, 0, ClientSize
.Width
, ClientSize
.Height
)
57 Me.realGraphics
= Me.CreateGraphics()
61 Me.thread
= New Thread(AddressOf
Me.RunMe
)
66 'Form overrides dispose to clean up the component list.
67 Protected Overloads Overrides
Sub Dispose(ByVal disposing
As Boolean)
69 MyBase
.Dispose(disposing
)
73 'NOTE: The following procedure is required by the Windows Form Designer
74 'It can be modified using the Windows Form Designer.
75 'Do not modify it using the code editor.
76 Private Sub InitializeComponent()
80 Me.BackColor
= System
.Drawing
.Color
.SlateBlue
81 Me.ClientSize
= New System
.Drawing
.Size(240, 295)
86 Public Shared
Sub Main()
88 Application
.Run(New BubbleForm())
94 Protected Overloads Overrides
Sub OnResize(ByVal e
As EventArgs
)
96 Me.cachedClientSize
= Me.ClientSize
101 EraseAll(Me.offscreenGraphics
)
103 Dim bubble
As Integer
104 For bubble
= 0 To MaxBubbles
- 1
105 Me.bubbles(bubble
).DoTick(cachedClientSize
)
108 RedrawAll(Me.offscreenGraphics
)
109 RefreshAll(Me.realGraphics
)
113 Private Sub RefreshAll(ByVal graphicsPhys
As Graphics
)
117 Dim bubble
As Integer
118 For bubble
= 0 To MaxBubbles
- 1
119 rc
= Me.bubbles(bubble
).WholeBounds
120 graphicsPhys
.DrawImage(Me.offscreenBitmap
, rc
.X
, rc
.Y
, rc
, GraphicsUnit
.Pixel
)
125 Private Sub RedrawAll(ByVal graphics
As Graphics
)
127 Dim bubble
As Integer
128 For bubble
= 0 To MaxBubbles
- 1
129 Me.bubbles(bubble
).Draw(graphics
)
134 Private Sub EraseAll(ByVal graphics
As Graphics
)
136 Dim bubble
As Integer
137 For bubble
= 0 To MaxBubbles
- 1
138 Me.bubbles(bubble
).EraseSub(graphics
, Me.backgroundBrush
)
151 Private Sub BubbleForm_MouseDown(ByVal sender
As Object, ByVal e
As System
.Windows
.Forms
.MouseEventArgs
) Handles MyBase
.MouseDown
158 Private Sub BubbleForm_Closed(ByVal sender
As Object, ByVal e
As System
.EventArgs
) Handles MyBase
.Closed