added samples
[windows-sources.git] / sdk / samples / FrameworkSamples / NETCF / Technologies / Bubble / vb / bubble / bubbleform.vb
blobf1786b517e5a4f2be412fe895a42d9f4d22f6ab4
1 ' =====================================================================
2 ' File: BubbleForm.vb
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
15 ' PARTICULAR PURPOSE.
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 "
39 Public Sub New()
41 MyBase.New()
43 'This call is required by the Windows Form Designer.
44 InitializeComponent()
46 'Additional initialization
47 Dim bubble As Integer
48 For bubble = 0 To MaxBubbles - 1
49 Me.bubbles(bubble) = New Bubble()
50 Me.bubbles(bubble).Init(ClientSize)
51 Next bubble
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()
59 Me.isRunning = True
61 Me.thread = New Thread(AddressOf Me.RunMe)
62 Me.thread.Start()
64 End Sub
66 'Form overrides dispose to clean up the component list.
67 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
69 MyBase.Dispose(disposing)
71 End Sub
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()
78 'BubbleForm
80 Me.BackColor = System.Drawing.Color.SlateBlue
81 Me.ClientSize = New System.Drawing.Size(240, 295)
82 Me.Text = "Bubbles"
84 End Sub
86 Public Shared Sub Main()
88 Application.Run(New BubbleForm())
90 End Sub
92 #End Region
94 Protected Overloads Overrides Sub OnResize(ByVal e As EventArgs)
95 MyBase.OnResize(e)
96 Me.cachedClientSize = Me.ClientSize
97 End Sub
99 Private Sub DoTick()
101 EraseAll(Me.offscreenGraphics)
103 Dim bubble As Integer
104 For bubble = 0 To MaxBubbles - 1
105 Me.bubbles(bubble).DoTick(cachedClientSize)
106 Next bubble
108 RedrawAll(Me.offscreenGraphics)
109 RefreshAll(Me.realGraphics)
111 End Sub
113 Private Sub RefreshAll(ByVal graphicsPhys As Graphics)
115 Dim rc As Rectangle
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)
121 Next bubble
123 End Sub
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)
130 Next bubble
132 End Sub
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)
139 Next bubble
141 End Sub
143 Private Sub RunMe()
145 While Me.isRunning
146 Me.DoTick()
147 End While
149 End Sub
151 Private Sub BubbleForm_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
153 Me.isRunning = False
154 Me.Close()
156 End Sub
158 Private Sub BubbleForm_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
160 Me.isRunning = False
162 End Sub
164 End Class
166 End Namespace