Results 1 to 4 of 4

Thread: Event sequencing problem: Need Expert help.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Event sequencing problem: Need Expert help.

    This is difficult to describe and I hope some serious guru can help me.

    My application is erasing an image in a PictureBox due to some control flow or event sequencing problem. I suspect that event triggering requires some Windows OS activity, probably using interrupt logic. I also suspect that the OS activity is not fast enough to prevent certain sequencing problems.

    I have an application which draws an image in a PictureBox. While the Draw Subroutine is active, Focus gets set to the PictureBox, which seems to be reasonable.

    The PictureBox Lost Focus Event is used to trigger activity which erases the picture.

    To prevent the obvious problem, the Draw Subroutine sets a Boolean variable (DrawingInProgress) to True, and the PictureBox Lost Focus Subroutine tests that Boolean variable, intending to avoid erasing the image at the wrong time.

    After the Draw Subroutine is finished generating the image, it sets focus to a Command Button, causing the PictureBox Lost Focus Subroutine to activate. After setting Focus to the Command Button, the Draw Subroutine resets DrawingInProgress to False.

    I expected the above code sequence to avoid erasure of the image, but it did not.

    I wrote some debugging code which stored data in an array to indicate the order of code execution and event triggering. The data indicated that the PictureBox Lost Focus Subroutine activated after the Boolean variable was reset to False.

    The following suggests the code being executed.
    VB Code:
    1. Private Sub FractalPainter()
    2. [b]. . .[/b]
    3. DrawingInProgress = True
    4.  
    5. ‘Code to generate the image using PSet
    6.  
    7. cmdShuffle.SetFocus
    8. ‘A few lines of code
    9. DrawingInProgress = False
    10. ‘A few lines of code
    11. End Sub
    12. [b]. . .[/b]
    13. Private Sub pixFractal_LostFocus()
    14.  
    15. If DrawingInProgress Then
    16.         Exit Sub
    17.     End If
    18. ‘Code which erases image
    19.  
    20. End Sub
    The Lost Focus Subroutine finds the Boolean to be false and erases the image.

    Does anybody understand my problem?

    Does anybody have a suggestion about what to do?
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  2. #2
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    All u need is a DoEvents command after cmdShuffle.SetFocus
    VB Code:
    1. cmdShuffle.SetFocus
    2. [b]DoEvents[/b]
    3. ‘A few lines of code
    4. DrawingInProgress = False
    5. ‘A few lines of code
    ps it isn't usually a good idea to use the LostFocus event for program control as it actually occurs 'before' the relevant object loses focus
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    BeachBum: DoEvents looked like a good idea. I tried it and it seems to have fixed the problem.

    Thanx much for the advice. I hope it is a solid fix.

    You said the following.
    ps it isn't usually a good idea to use the LostFocus event for program control as it actually occurs 'before' the relevant object loses focus
    Interesting! When does it occur?

    After painting a Fractal Image in a Picture Box, the application provides a mechanism for the user to indicate a rectangle to Zoom into, magnifying that part of the image. Once the user has indicated the area of interest, it seems intuitive for him to click on a Command Button to paint the indicated area. That cause focus to shift from the Picture Box. The Lost Focus event seems like a good way to trigger the code required to set up for the new rectangle of interest.

    Do you have another suggestion?
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    I have also had problems with LostFocus, it doesn't necessarily behave the way you expect it to.

    If I understand your situation right, the picture is a rectangular area. The user clicks and drags a rectangle which will then be expanded to fill the area, or else the user clicks a point in the current image. Either way, it seems like the mouse messages will give you all the information you need.

    If the user is dragging a rectangle on the current image, why not skip the command button, and re-draw the image when the dragging is complete (I forget the event, mouseUp or something). This would work for zooming in, but would have problems if the user has other options rather than zooming in when they select a part of the image.

    Zooming out would be a button click.

    Is that in the area?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width