Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Infinite loop - Resizing Form

Infinite loop - Resizing Form

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    watagal
    wrote on last edited by
    #1

    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

    R U D W 4 Replies Last reply
    0
    • W watagal

      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

      R Offline
      R Offline
      Richard_Wolf
      wrote on last edited by
      #2

      You'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. :)

      1 Reply Last reply
      0
      • W watagal

        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

        U Offline
        U Offline
        User 2192404
        wrote on last edited by
        #3

        look 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

        1 Reply Last reply
        0
        • W watagal

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          OK. 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 of Checked changes to True, right? This fires the CheckedChanged event, not because the box was checked, but because the value of Checked was altered. Now, in your code, you check the value of Checked, then change it to the opposite of what it is set to. This fires the CheckedChanged event again because, well, you changed it! Guess what happens next... Why are you changing the value of Checked 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 Class

          RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          • W watagal

            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

            W Offline
            W Offline
            watagal
            wrote on last edited by
            #5

            Dooh! I promise to think next time before asking. No I'm not blond! Thanks to all!! Thanks, Karen Nooobie to OOP and VB.Net 2005

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups