|
-
Jun 22nd, 2003, 11:44 PM
#1
Thread Starter
Frenzied Member
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:
Private Sub FractalPainter()
[b]. . .[/b]
DrawingInProgress = True
‘Code to generate the image using PSet
cmdShuffle.SetFocus
‘A few lines of code
DrawingInProgress = False
‘A few lines of code
End Sub
[b]. . .[/b]
Private Sub pixFractal_LostFocus()
If DrawingInProgress Then
Exit Sub
End If
‘Code which erases image
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.
-
Jun 23rd, 2003, 04:34 AM
#2
PowerPoster
All u need is a DoEvents command after cmdShuffle.SetFocus
VB Code:
cmdShuffle.SetFocus
[b]DoEvents[/b]
‘A few lines of code
DrawingInProgress = False
‘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
-
Jun 23rd, 2003, 07:14 PM
#3
Thread Starter
Frenzied Member
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.
-
Jun 23rd, 2003, 08:50 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|