Could someone please tell me if I am doing this right. I know I am not because it won't work but am I even close? I am trying to take a png file and use that to make a balloon in that shape on a pictureBox(someone suggested yesterday). The bubbles are supposed to float to the top of the vat and then pop. I looked at my book and tried it from there. I put a pictureBox on my panel and then imported the (andy.png) into the pictureBox. When I run it a page opens up (application designer.vb) with a line with green in it. Is it possible to do what I need to do this way? I am really lost. Any help would be greatly appreciated.
I have a bunch of stuff commented out.
Form1.vb:
Public Class Form1
Private Foam As New List(Of Bubble)
Private CurrentAge As Integer
Private Rand As New Random
Dim x_intercept(0, 0)
Dim y_intercept(0, 0)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timBubbleTimer.Interval = 100
timBubbleTimer.Enabled = False
pnlVat.BackColor = Color.LightGray
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Foam = New List(Of Bubble)
CurrentAge = 0
Dim g As Graphics = pnlVat.CreateGraphics
g.FillRectangle(New SolidBrush(Color.LightGray), pnlVat.DisplayRectangle)
timBubbleTimer.Enabled = True
timBubbleTimer.Start()
End Sub
Private Sub timBubbleTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timBubbleTimer.Tick, PictureBox1.Move
CurrentAge += 1
Dim PX As Integer
Dim PY As Integer
PX = 10
PY = 10
Static Count
Count = (Count + 1) Mod 2
If Count = 1 Then
PictureBox1.Image = Image.FromFile("Andy.png")
Else
PictureBox1.Image = Image.FromFile("NoAndy.png")
End If
PictureBox1.SetBounds(PictureBox1.Left + PX, PictureBox1.Top + PY, 0, 0)
If (PictureBox1.Top + PictureBox1.Height) > Height Then PY = -PY
If PictureBox1.Top < 0 Then PY = -PY
If (PictureBox1.Left + PictureBox1.Width) > Width Then PX = -PX
If PictureBox1.Left < 0 Then PX = -PX
Count = (Count + 1) Mod 3
Select Case Count
Case 0
PictureBox1.Image = Image.FromFile("Andy.png")
Case 1
PictureBox1.Image = Image.FromFile("NoAndy.png")
End Select
'Dim MaxX, MaxY As Integer
'MaxX = pnlVat.Width
'MaxY = pnlVat.Height
'Dim g As Graphics
'g = pnlVat.CreateGraphics
'Dim p As New Point(0, 0)
'PX = Rand.Next(4, MaxX - 4)
'PY = Rand.Next(MaxY - 34, MaxY - 4)
'p = New Point(PX, PY)
'Foam.Add(New Bubble(p, Brush.newColor, Pen.DimGray))
'pnlVat.Refresh()
'For i As Integer = 0 To Foam.Count - 1 Step 1
' If Foam(i).GetLocation.X > MaxX Then
'Foam(i).Remove(g)
'Foam(i).GetLocation()
' End If
'If Foam(i).GetLocation.Y < 0 Then
' Foam(i).Remove(g)
' Foam(i).GetLocation()
'End If
'' Foam(i).Remove(g)
'Foam(i).Move()
'Foam(i).Draw(g)
'Foam(i).Grow()
'Next
' Add code here to create, move, resize, erase and redraw all the bubbles in the Foam list
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
timBubbleTimer.Stop()
timBubbleTimer.Enabled = False
End Sub
End Class
Bubble.vb
Public Class Bubble
Private BubSize As Integer
Private BubColor As Color
Private BubOutlineColor As Color
Private BubLocation As Point
Private BubAge As Integer
Shared Graphics As Graphics
Public Sub New(ByVal NewLoc As Point, ByVal NewColor As Color, ByVal NewOutlineColor As Color)
'Dim New List As New Bubble
' Initialize the attributes of a new bubble here
Dim g As Graphics = Bubble.Graphics
BubColor = Color.Aqua
BubOutlineColor = Color.AntiqueWhite
'BubLocation = (y)
BubAge = 0
BubSize = (1)
End Sub
Public Function GetLocation() As Point
Return BubLocation
End Function
Public Function GetSize() As Integer
Return BubSize
End Function
Public Sub Move()
Move()
' Add code here to change a bubble's location
End Sub
Public Sub Remove(ByVal g As Graphics)
Remove(g)
' Add code here to remove a bubble from the list
End Sub
Public Sub Draw(ByVal g As Graphics) ' Add code to draw the current bubble
'Dim myPng As Image("andy.png", "noAndy.png")
'Dim g As Graphics = Graphics.FromHwnd(PictureBox)
''g.DrawImage(myPNG, 150, 200)
'Dim myBrush As System.Drawing.Brush()
'Dim BubGraphics As System.Drawing.Graphics
'BubGraphics = Bubble.CreateGraphics()
'formGraphics.DrawEllipse(Brush, New Rectangle(0, 0, 200, 300))
''myBrush.Dispose()
'BubGraphics.Dispose()
' Dim width As Integer = bm.Width - (bm.Width * percentResize) 'image width.
' Dim height As Integer = bm.Height - (bm.Height * percentResize) 'image height
' g.DrawImage(bm, New Rectangle(0, 0, width, height), New Rectangle(0, 0, bm.Width, _
'bm.Height), GraphicsUnit.Pixel)
' g.Dispose()
' bm.Dispose()
End Sub
Public Sub UnDraw(ByVal g As Graphics)
UnDraw(g)
' Add code to erase the current bubble from the display
End Sub
Public Sub Grow()
BubSize += 1
End Sub
End Class
Application designer.vb
<auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.261
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.Suds.Form1 This is the one that keeps showing up.
End Sub
End Class
End Namespace