Recreating a Picture Box

Dispose, Dim x As New

Page 1 of 1

1 Replies - 1815 Views - Last Post: 20 December 2008 - 02:32 PM Rate Topic: -----

#1 TheFeignedTruth   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 20-December 08

Recreating a Picture Box

Post icon  Posted 20 December 2008 - 02:29 PM

I am looking for how to recreate an object after it was disposed. My attemt is to name the new picture box the same as the old yet the picture box is not recognized by the program as the same. How do a make the program recoginize it as the same or add its own section of code.
Here is my entire racing program's code; I'm not sure what you need and I want any other tidbits of advice you might have.

 
Public Class frmMain

    Dim victoryOne As Integer
    Dim victoryTwo As Integer
    Dim victoryThree As Integer
    Dim victoryFour As Integer

    Dim bet As Double
    Dim cash As Double

    Dim disp As Integer

    Dim max As Double

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Application.Exit()

    End Sub
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        max = InputBox("Insert maximum speed for racing", "MAX", "50")
         
        victoryOne = 0
        victoryTwo = 0
        victoryThree = 0
        victoryFour = 0
        cboVictors.Items.Add("Book One - " & victoryOne & " Victories")
        cboVictors.Items.Add("Book Two - " & victoryTwo & " Victories")
        cboVictors.Items.Add("Book Three - " & victoryThree & " Victories")
        cboVictors.Items.Add("Book Four - " & victoryFour & " Victories")

    End Sub

    Private Sub mnuRaceStartRace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRaceStartRace.Click
        tmrMove.Enabled = True

    End Sub

    Private Sub mnuRaceResetPlanes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRaceResetPlanes.Click
        picOne.Left = 15
        picOne.Top = 31
        picTwo.Left = 15
        picTwo.Top = 148
        picThree.Left = 15
        picThree.Top = 272
        picFour.Left = 15
        picFour.Top = 390

        tmrMove.Enabled = False



    End Sub

    Private Sub mnuRaceChangeMaxSpeed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRaceChangeMaxSpeed.Click
        max = InputBox("Insert new maximum speed for racing", "MAX", max)
    End Sub

    Private Sub mnuRaceExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRaceExit.Click
        Application.Exit()

    End Sub

    Private Sub tmrMove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
        Dim one As Double
        Dim two As Double
        Dim three As Double
        Dim four As Double

        Randomize()
        one = Int(max * Rnd()) + 1
        Randomize()
        two = Int(max * Rnd()) + 1
        Randomize()
        three = Int(max * Rnd()) + 1
        Randomize()
        four = Int(max * Rnd()) + 1

        picOne.Left += one
        picTwo.Left += two
        picThree.Left += three
        picFour.Left += four

        If picOne.Location.X >= 517 Or picTwo.Location.X >= 517 Or picThree.Location.X >= 517 Or picFour.Location.X >= 517 Then
            tmrMove.Stop()
            If picOne.Location.X > picTwo.Location.X And picOne.Location.X > picThree.Location.X And picOne.Location.X > picFour.Location.X Then
                MessageBox.Show("Book One Has Won", "The Victor", MessageBoxButtons.OK)
                cboVictors.Items.Remove("Book One - " & victoryOne & " Victories")
                victoryOne += 1
                cboVictors.Items.Add("Book One - " & victoryOne & " Victories")
                            ElseIf picTwo.Location.X > picOne.Location.X And picTwo.Location.X > picThree.Location.X And picTwo.Location.X > picFour.Location.X Then
                MessageBox.Show("Book Two Has Won", "The Victor", MessageBoxButtons.OK)
                cboVictors.Items.Remove("Book Two - " & victoryTwo & " Victories")
                victoryTwo += 1
                cboVictors.Items.Add("Book Two - " & victoryTwo & " Victories")
            ElseIf picThree.Location.X > picOne.Location.X And picThree.Location.X > picTwo.Location.X And picThree.Location.X > picFour.Location.X Then
                MessageBox.Show("Book Three Has Won", "The Victor", MessageBoxButtons.OK)
                cboVictors.Items.Remove("Book Three - " & victoryThree & " Victories")
                victoryThree += 1
                cboVictors.Items.Add("Book Three - " & victoryThree & " Victories")
            Else
                MessageBox.Show("Book Four Has Won", "The Victor", MessageBoxButtons.OK)
                cboVictors.Items.Remove("Book Four - " & victoryFour & " Victories")
                victoryFour += 1
                cboVictors.Items.Add("Book Four - " & victoryFour & " Victories")
            End If
        End If

    End Sub

    Private Sub mnuResetCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuResetCount.Click
        victoryOne = 0
        victoryTwo = 0
        victoryThree = 0
        victoryFour = 0
        cboVictors.Items.Clear()
        cboVictors.Items.Add("Book One - " & victoryOne & " Victories")
        cboVictors.Items.Add("Book Two - " & victoryTwo & " Victories")
        cboVictors.Items.Add("Book Three - " & victoryThree & " Victories")
        cboVictors.Items.Add("Book Four - " & victoryFour & " Victories")

    End Sub

    Private Sub btnDis_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDis.Click
        If picOne.Location.X < picTwo.Location.X And picOne.Location.X < picThree.Location.X And picOne.Location.X < picFour.Location.X Then
            picOne.Dispose()
            disp = 1
        ElseIf picTwo.Location.X < picOne.Location.X And picTwo.Location.X < picThree.Location.X And picTwo.Location.X < picFour.Location.X Then
            picTwo.Dispose()
            disp = 2
        ElseIf picThree.Location.X < picOne.Location.X And picThree.Location.X < picTwo.Location.X And picThree.Location.X < picFour.Location.X Then
            picThree.Dispose()
            disp = 3
        ElseIf picFour.Location.X < picOne.Location.X And picFour.Location.X < picTwo.Location.X And picFour.Location.X < picThree.Location.X Then
            picFour.Dispose()
            disp = 4
        Else
            On Error Resume Next
        End If
    End Sub

    Private Sub btnCre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCre.Click
        Select Case disp
            Case 1
                Dim picOne As New PictureBox
                picOne.Left = 15
                picOne.Top = 31
                Me.Controls.Add(picOne)
                picOne.Load("C:\Documents and Settings\Brian Kramer\My Documents\Visual Studio 2008\Projects\The Race Is On\The Race Is On\Resources\Azuth_symbol.jpg")
                picOne.SizeMode = PictureBoxSizeMode.StretchImage
                picOne.Width = 100
                picOne.Height = 100

                'register as new pic for race
            Case 2
                Dim picTwo As New PictureBox
                picTwo.Left = 15
                picTwo.Top = 148
                Me.Controls.Add(picTwo)
                'change pathes
                picTwo.Load("C:\Documents and Settings\Brian Kramer\My Documents\Visual Studio 2008\Projects\The Race Is On\The Race Is On\Resources\Azuth_symbol.jpg")
                picTwo.SizeMode = PictureBoxSizeMode.StretchImage
                picTwo.Width = 100
                picTwo.Height = 100
            Case 3
                Dim picThree As New PictureBox
                picThree.Left = 15
                picThree.Top = 272
                Me.Controls.Add(picThree)
                picThree.Load("C:\Documents and Settings\Brian Kramer\My Documents\Visual Studio 2008\Projects\The Race Is On\The Race Is On\Resources\Azuth_symbol.jpg")
                picThree.SizeMode = PictureBoxSizeMode.StretchImage
                picThree.Width = 100
                picThree.Height = 100
            Case 4
                Dim picFour As New PictureBox
                picFour.Left = 15
                picFour.Top = 390
                Me.Controls.Add(picFour)
                picThree.Load("C:\Documents and Settings\Brian Kramer\My Documents\Visual Studio 2008\Projects\The Race Is On\The Race Is On\Resources\Azuth_symbol.jpg")
                picThree.SizeMode = PictureBoxSizeMode.StretchImage
                picFour.Width = 100
                picFour.Height = 100
            Case Else
                On Error Resume Next
        End Select
        
    End Sub
End Class


Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Recreating a Picture Box

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Recreating a Picture Box

Posted 20 December 2008 - 02:32 PM

This is VB.NET code, so this is being moved to the VB.NET forum :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1