Infinite loop - Resizing Form
-
Greetings! The following code sends my program into a infinite loop.
Public Class LogFotosForm Private Sub PreviewFotoChkBx_CheckedChanged( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles PreviewFotoChkBx.CheckedChanged If PreviewFotoChkBx.Checked Then PreviewFotoChkBx.Checked = False Me.Width = 320 Else PreviewFotoChkBx.Checked = True Me.Width = 450 End If End Sub End Class
I want to resize my form when the checkbox changes - once the checkbox is True. Should I be using a different event? Thanks, Karen Nooobie to OOP and VB.Net 2005 -
Greetings! The following code sends my program into a infinite loop.
Public Class LogFotosForm Private Sub PreviewFotoChkBx_CheckedChanged( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles PreviewFotoChkBx.CheckedChanged If PreviewFotoChkBx.Checked Then PreviewFotoChkBx.Checked = False Me.Width = 320 Else PreviewFotoChkBx.Checked = True Me.Width = 450 End If End Sub End Class
I want to resize my form when the checkbox changes - once the checkbox is True. Should I be using a different event? Thanks, Karen Nooobie to OOP and VB.Net 2005You're already In the "Changed" event, you don't need to change the valud a second time, doing so causes the event to be refired, and since you're toggling the value you get an infinite loop. Take out the "PreviewFotoChkBx.Checked" lines and I think it will do what you want it to do. :)
-
Greetings! The following code sends my program into a infinite loop.
Public Class LogFotosForm Private Sub PreviewFotoChkBx_CheckedChanged( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles PreviewFotoChkBx.CheckedChanged If PreviewFotoChkBx.Checked Then PreviewFotoChkBx.Checked = False Me.Width = 320 Else PreviewFotoChkBx.Checked = True Me.Width = 450 End If End Sub End Class
I want to resize my form when the checkbox changes - once the checkbox is True. Should I be using a different event? Thanks, Karen Nooobie to OOP and VB.Net 2005look the problem is u r using the function PreviewFotoChkBx_CheckedChanged which handels the checkbox checked property.and in it the if condition you r changeing the property againg so function calles it self again and ur programe goes in infinite loop. insted of using checked property(handling checkedchanged)use click then it will work fine.best of luck:) GET BACK 2 ME
-
Greetings! The following code sends my program into a infinite loop.
Public Class LogFotosForm Private Sub PreviewFotoChkBx_CheckedChanged( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles PreviewFotoChkBx.CheckedChanged If PreviewFotoChkBx.Checked Then PreviewFotoChkBx.Checked = False Me.Width = 320 Else PreviewFotoChkBx.Checked = True Me.Width = 450 End If End Sub End Class
I want to resize my form when the checkbox changes - once the checkbox is True. Should I be using a different event? Thanks, Karen Nooobie to OOP and VB.Net 2005OK. I have to giggle a little bit here. Follow your code. This is the
CheckedChanged
event right? Well, if the user clicks on a empty checkbox, the value ofChecked
changes toTrue
, right? This fires theCheckedChanged
event, not because the box was checked, but because the value ofChecked
was altered. Now, in your code, you check the value ofChecked
, then change it to the opposite of what it is set to. This fires theCheckedChanged
event again because, well, you changed it! Guess what happens next... Why are you changing the value ofChecked
at all? Don't! As far as I can tell, you don't need to do it for any reason. All your doing is changing the size of the form based on whether the checkbox is checked or not. Why is your code changing the checkbox value? Eliminate the lines that are changing the checkbox:Public Class LogFotosForm
Private Sub PreviewFotoChkBx_CheckedChanged( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles PreviewFotoChkBx.CheckedChanged
If PreviewFotoChkBx.Checked Then
Me.Width = 320
Else
Me.Width = 450
End If
End Sub
End ClassRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Greetings! The following code sends my program into a infinite loop.
Public Class LogFotosForm Private Sub PreviewFotoChkBx_CheckedChanged( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles PreviewFotoChkBx.CheckedChanged If PreviewFotoChkBx.Checked Then PreviewFotoChkBx.Checked = False Me.Width = 320 Else PreviewFotoChkBx.Checked = True Me.Width = 450 End If End Sub End Class
I want to resize my form when the checkbox changes - once the checkbox is True. Should I be using a different event? Thanks, Karen Nooobie to OOP and VB.Net 2005