paint event

ideprize

Well-known member
Joined
Oct 19, 2011
Messages
97
Programming Experience
10+
Hi ALL

I have some conceptual questions for the program that I have converted from VB6 to VB.net is working but there are elements of it that I really don't "see".
I have a form with two picture boxes; picture1 and picture2; picture1 is a much smaller picture box that is totally contained by picture2.

The program via a textbox captures the name of a disk image file (TIF) and transfers that file to picture1 by way of the following 2 commands

Picture1.SizeMode = PictureBoxSizeMode.StretchImage
Picture1.Image = Image.FromFile(fileName)

the disk file image is transferred and expanded to the dimensions of the picture box picture2!
What mechanism stretches the image to the dimensions of the picture box picture2 when it is transferred to picture1?

This image transfer happens in the textbox_leave event; but the "picture2_paint" event (which presents the image) does not fire until the textbox_validating event is exited?
What I would like to understand is why did the original programmer use this picture1, picture2 choreography; is this inside, outside picture box relationship the "mechanism" that provides the correct display size; why does the picture2_paint event fire when picture1 is assigned the image and lastly, why does the picture2_paint event wait for the textbox_validating event to be exited before it fires.

My education is in need of updating. Any help would be greatly appreciated.
 
What mechanism stretches the image to the dimensions of the picture box
The image is painted from the Picturebox internal code for OnPaint method based on the size mode. Any change of state that result in different visual appearance will cause the control to invalidate itself.
This image transfer happens in the textbox_leave event; but the "picture2_paint" event (which presents the image) does not fire until the textbox_validating event is exited?
Event handlers are called one at a time synchronously, no other code can be performed on UI thread while code for an event is handled. As such no paint code can be performed while UI thread is busy processing other things.
 
Thanks JohnH for your response. Got the second part of your response loud and clear - all of the events relative to the textbox control will be processed prior to the events of the picture2 control. The first part of your answer, however, still has me scratching my head? I think you are saying the image was stretched due to the sizmode.stretchimage method and I understood that part. What I don't understand is why was the stretch extended to the dimensions of the Picture2 picture box - the stretchimage method is "attached" to the picture1 picture box. Also why is the picture2 paint event being used to display the image when again it was assigned to the picture1 picture box (thankfully by the way). I can only assume when you have nested picture boxes all methods and events apply to the "dominant" picture box (the one on the outside). Additionally, I don't understand why the programmer used TWO picture boxes - why not just use picture box picture2!

Respectfully,
Gordon Haas
 
Picturebox has no ambient properties (apart from Control.BackColor), its behaviour is only determined by its own state.
I don't understand exactly what you are trying to describe above, but a control may invalidate children and cause them to repaint themselves, a control will generally not invalidate its parent.
 
Again, thanks JohnH

Since your first response I have been doing a lot of reading on invalidate, refresh, and update. I now understand what you meant by saying when the control is invalidated and what that action causes. What I inherited was a form that primarily displays scanned images. The form consist of two nested picture boxes - picture1 (the contained picture box) and picture2 (the containing picture box). When the image is read it is transferred to picture1 then stretched with the end result of "filling" picture2. This seems to be telling me that the child control has invalidated the parent control - somehow. When the actual "painting" is done it is the picture2 paint event that does it. What I am really curious about is why did the original programmer use two nested pictureboxes in the first place? It was originally written in VB6. I converted it to VB.net - this was my first submersion into VB!

Respectfully,
Gordon Haas
 
Back
Top