Jump to content

Help with VB Project - Can't fix error

Go to solution Solved by aom,

I found my problem, while I turn off the visibility of the panel, the controls inside of it were still enabled and overrided my keypress controls. So all i had to do was also disable the panel too. Thanks for your help though.

Basically, I am making a game for a project in my CompSci class with VB.NET.

The game originally could move left and right, but once i added in a menu and stuff, it broke and you cannot move anymore. I honestly do not know what part of it could possibly interfere with it though.

The form consists of two panels, one for the game world and the other for the menu, pressing btnlevel1, hides the menu panel, and shows the game panel.

 

EDIT: If I set visibility of the game panel to true at Form_Load, it works. However, it doesn't work when visibility is set after the fact.

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown        If panelLevel.Visible = True Then            If e.KeyCode = Keys.Left Then                tmrLeft.Enabled = True                tmrRight.Enabled = False            ElseIf e.KeyCode = Keys.Right Then                tmrRight.Enabled = True                tmrLeft.Enabled = False            End If        End If    End Sub    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp        If panelLevel.Visible = True Then            If e.KeyCode = Keys.Left Then                tmrLeft.Enabled = False            ElseIf e.KeyCode = Keys.Right Then                tmrRight.Enabled = False            End If        End If    End Sub    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Me.AutoScroll = False        panelLevel.Visible = False        panelStartMenu.Visible = True    End Sub    Private Sub tmrLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLeft.Tick        Dim Objects() As PictureBox = {pb1, pb2, pb3}        For index As Integer = 0 To Objects.Length - 1            Objects(index).Left += 5        Next    End Sub    Private Sub tmrRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRight.Tick        Dim Objects() As PictureBox = {pb1, pb2, pb3}        For index As Integer = 0 To Objects.Length - 1            Objects(index).Left -= 5        Next    End Sub    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click        panelStartMenu.Visible = False        panelLevel.Visible = True    End Sub    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click        End    End Sub 

Thanks in advance. (and I know there isn't much to it, mostly because I still don't know what exactly its going to be yet)

 

 

Link to comment
https://linustechtips.com/topic/326564-help-with-vb-project-cant-fix-error/
Share on other sites

Link to post
Share on other sites

Basically, I am making a game for a project in my CompSci class with VB.NET.

The game originally could move left and right, but once i added in a menu and stuff, it broke and you cannot move anymore. I honestly do not know what part of it could possibly interfere with it though.

The form consists of two panels, one for the game world and the other for the menu, pressing btnlevel1, hides the menu panel, and shows the game panel.

 

EDIT: If I set visibility of the game panel to true at Form_Load, it works. However, it doesn't work when visibility is set after the fact.

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

Thanks in advance. (and I know there isn't much to it, mostly because I still don't know what exactly its going to be yet)

What about this? 

 

I think it is because when you close the panel you are not setting

panelLevel.Visible = True
once the menu is closed again. 
I do not really know VB.net well (and it has been a long time since I have used it). 
 
try this (again I am not sure if this is fitting for VB.net but you might get the idea)
if panelStartMenu.Visible = True Then    panelLevel.Visible = False    panelStartMenu.Visible = TrueElseIf panelStartMenu.Visible = False Then    panelLeve.Visible = True    panelStartMenu.Visible = Falseend

If this does not work then try the same but with "btnlvl1" instead of "panelStartMenu.Visible" 

CPU: i5 4670k @ 3.4GHz + Corsair H100i      GPU: Gigabyte GTX 680 SOC (+215 Core|+162 Mem)     SSD: Kingston V300 240GB (OS)      Headset: Logitech G930 

Case: Cosair Vengance C70 (white)                RAM: 16GB TeamGroup Elite Black DDR3 1600MHz       HDD: 1TB WD Blue                              Mouse: Logitech G602

OS: Windows 7 Home Premium                       PSUXFX Core Edition 750w                                                Motherboard: MSI Z97-G45               Keyboard: Logitech G510

Link to post
Share on other sites

I found my problem, while I turn off the visibility of the panel, the controls inside of it were still enabled and overrided my keypress controls. So all i had to do was also disable the panel too. Thanks for your help though.

 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×