Hi,
I was hoping that somebody could tell me how to program a "new" function for a menustrip. I want this to reload my program.
Private Sub NewGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewGameToolStripMenuItem.Click
Dim Monopoly As New Monopoly
Monopoly.Show()
Me.Close()
End Sub
That is what i have so far the only problem is that it opens a new program then closes the both of them. How do i distinguish the new form from the old or is there a way around this

Menustrip
mflexer
I mean what the form does when it is loading should do it again with the "NEW" command at the menu strip.
SomeGuyOnAComputer
that does work, but then when i go to exit the program the hidden from is still running in the background. Because i have Program shutdown mode set as "When last form closes". Is there another way
thanks
Connor
XJDM003
I was just fooling around with my code trying out both your ideas and now somehow ive messed up part of my code and i cant seem to figure out how to fix it...
I am trying to get the buy function to work with variable "rollcountercar" and variable "mypropertiesprice", my main form called "Monopoly" calls "BuyDialog" and is supposed to display the name and price of a property. I think that somehow the name of my main form maybe got changed because it seems that whenever BuyDialog trys the to call Monopoly it doesnt work. But when i go to the properties panel of Monopoly the name still says its the same. There are no errors in the program it just doesnt work. Exept for when running you program and click the buy button under BuyDialog the program crashes.
Below i have included only the code that seems relevant the the problem. I hope that my problem all makes sense.
Thanks alot,
Connor
______________________________________________________________________
Public Class Monopoly
Public mysquaresx(40) As Integer
Public mysquaresy(40) As Integer
Public rollnum1 As Integer
Public rollcounterhat As Integer
Public rollcountercar As Integer
Public player1carturn As Boolean
Public myproperties(28) As Integer
Public mypropertiesprice(28) As Integer
Public mypropertiesrent(28) As Integer
Public mypropertiesname(28) As String
Public mypropertiesmortgage(28) As Integer
Public carmoney As Integer
Public hatmoney As Integer
Dim mymenu As MenuStrip
' name
mypropertiesname(1) = "Mediterranean Avenue"
mypropertiesname(2) = "Baltic Avenue"
mypropertiesname(4) = "Reading Railroad"
mypropertiesname(5) = "Vermont Avenue"
mypropertiesname(6) = "Connecticut Avenue"
mypropertiesname(8) = "St. Charles Place"
mypropertiesname(9) = "Electric Company"
mypropertiesname(10) = "States Avenue"
mypropertiesname(11) = "Pennsylvania Railroad"
mypropertiesname(12) = "St. James Place"
mypropertiesname(13) = "Tennessee Avenue"
mypropertiesname(15) = "Kentucky Avenue"
mypropertiesname(16) = "Illinois Avenue"
mypropertiesname(17) = "B. & O. Railroad"
mypropertiesname(18) = "Atlantic Avenue"
mypropertiesname(19) = "Water Works"
mypropertiesname(20) = "Marvin Gardens"
mypropertiesname(22) = "Pacific Avenue"
mypropertiesname(23) = "Pennsylvania Avenue"
mypropertiesname(24) = "Short Line"
mypropertiesname(25) = "Park Place"
mypropertiesname(27) = "Boardwalk"
' price
mypropertiesprice(1) = 60
mypropertiesprice(2) = 60
mypropertiesprice(4) = 200
mypropertiesprice(5) = 100
mypropertiesprice(6) = 120
mypropertiesprice(8) = 140
mypropertiesprice(9) = 150
mypropertiesprice(10) = 160
mypropertiesprice(11) = 200
mypropertiesprice(12) = 180
mypropertiesprice(13) = 200
mypropertiesprice(14) = 500
mypropertiesprice(15) = 220
mypropertiesprice(16) = 240
mypropertiesprice(17) = 200
mypropertiesprice(18) = 260
mypropertiesprice(19) = 150
mypropertiesprice(20) = 280
mypropertiesprice(22) = 300
mypropertiesprice(23) = 320
mypropertiesprice(24) = 200
mypropertiesprice(25) = 350
mypropertiesprice(27) = 400
Private Sub Roll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Roll.Click
Roll.Enabled = False
Endturn.Enabled = True
Buy.Enabled = True
Sell.Enabled = True
Trade.Enabled = True
Dim newloc As New System.Drawing.Point
rollnum1 = Rand(1, 6)
If player1carturn = True Then
rollcountercar = rollcountercar + rollnum1
TextBox1.Text = rollnum1
If rollcountercar > 28 Then
rollcountercar = rollcountercar - 28
End If
newloc.X = mysquaresx(rollcountercar)
newloc.Y = mysquaresy(rollcountercar)
PictureBox31.Location = newloc
If myproperties(rollcountercar) = 0 Then
Buy.Visible = True
Else
Buy.Visible = False
End If
Else
rollcounterhat = rollcounterhat + rollnum1
TextBox1.Text = rollnum1
If rollcounterhat > 28 Then
rollcounterhat = rollcounterhat - 28
End If
newloc.X = mysquaresx(rollcounterhat)
newloc.Y = mysquaresy(rollcounterhat)
PictureBox30.Location = newloc
If myproperties(rollcounterhat) = 0 Then
Buy.Visible = True
Else
Buy.Visible = False
End If
End If
Private Sub Buy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buy.Click
BuyDialog.Visible = True
BuyDialog.Focus()
End Sub
' BuyDialog Code
Public Class BuyDialog
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Monopoly.player1carturn = True Then
Label1.Text = "Welcome to " & Monopoly.mypropertiesname(Monopoly.rollcountercar) & ", would you like to buy it for $" & Monopoly.mypropertiesprice(Monopoly.rollcountercar)
Else
Label1.Text = "Welcome to " & Monopoly.mypropertiesname(Monopoly.rollcounterhat) & ", would you like to buy it for $" & Monopoly.mypropertiesprice(Monopoly.rollcounterhat)
End If
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Buy_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buy_Button.Click
If Monopoly.player1carturn = True And Monopoly.carmoney >= Monopoly.mypropertiesprice(Monopoly.rollcountercar) Then
Monopoly.myproperties(Monopoly.rollcountercar) = 1
Monopoly.carmoney = Monopoly.carmoney - Monopoly.mypropertiesprice(Monopoly.rollcountercar)
Me.Visible = False
Monopoly.Buy.Enabled = False
ElseIf Monopoly.player1carturn = False And Monopoly.hatmoney >= Monopoly.mypropertiesprice(Monopoly.rollcountercar) Then
Monopoly.myproperties(Monopoly.rollcounterhat) = 2
Monopoly.hatmoney = Monopoly.hatmoney - Monopoly.mypropertiesprice(Monopoly.rollcounterhat)
Me.Visible = False
Monopoly.Buy.Enabled = False
Else
MsgBox("You don't have enough money to purchase this")
Me.Visible = False
Monopoly.Buy.Enabled = False
End If
Monopoly.hatmoney1.Text = Monopoly.hatmoney
Monopoly.carmoney1.Text = Monopoly.carmoney
If Monopoly.player1carturn = True And Monopoly.carmoney >= Monopoly.mypropertiesprice(Monopoly.rollcountercar) Then
Monopoly.Carlistproperties.Items.Add(Monopoly.mypropertiesname(Monopoly.rollcountercar))
TradeDialog.Tradecarlistproperties.Items.Add(Monopoly.mypropertiesname(Monopoly.rollcountercar))
ElseIf Monopoly.player1carturn = False And Monopoly.hatmoney >= Monopoly.mypropertiesprice(Monopoly.rollcounterhat) Then
Monopoly.Hatlistproperties.Items.Add(Monopoly.mypropertiesname(Monopoly.rollcounterhat))
TradeDialog.Tradehatlistproperties.Items.Add(Monopoly.mypropertiesname(Monopoly.rollcounterhat))
End If
End Sub
End Class
Mike Greenway
Anyway i believe this is the right approach.
Fergnab
Well, I do not know then.
I made new project and added this:
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ClickDim x As New Form1
x.Show()
Me.Close()
End Sub
After I changed shutdown mode to "When last form closes", everything worked.
Haim Cohen
thanks,
connor
guy2006
You wouldn't happen to be looking for:
Application.Restart()
Thap
THIS IS YOUR CODE HERE WHEN THE FORMS LOAD
End Sub
Private Sub NEWToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NEWToolStripMenuItem.Click
AddHandler NEWToolStripMenuItem.Click, AddressOf Form1_Load
End Sub
The addHandler maybe help you! As i said i don;t know excatly what you want to do.
Big Cal
De_Stan,
don't you think there's error in your code
First time user clicks menu item, nothing will occur. Second time everything will be correct. Then, each next time user clicks this item, new handler will be added, and the Form1_Load sub will be called more than once.
Considering this approach, I would try this:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
THIS IS YOUR CODE HERE WHEN THE FORMS LOAD
End Sub
Private Sub NEWToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NEWToolStripMenuItem.Click
Form1_Load(Me, e)
End Sub
But it would be even better to gather all initialization code to one Sub and to call it from NEWToolStripMenuItem_Click.
hazz
Try to change Me.Close() to Me.Hide()
VB regards your first form as the main form in the application. So, if you close it, VB thinks that you want to close the entire application. So, you may want just to hide the first form instead of closing it.
Novelle
But it would be even better to gather all initialization code to one Sub and to call it from NEWToolStripMenuItem_Click.
You should do that!