Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Picturebox update, refresh, show give odd results -vb.net multiform, multimonitor

$
0
0

I have n forms each with a picture box in it. (And each on a different monitor).

The sole purpose of the picture box is to display bitmaps, which are assigned using 

  .PictureBox1.Image = Image.FromFile(PictureString)

inevitably, one of the n forms/pictureboxes fails to show a new image when the next collection of images is assigned.

In researching this problem, I've seen comments to the effect that this is a misuse of the picturebox control, which isn't intended for 'dynamic' graphics applications, and that custom controls consistent with multi-threading, event driven programming should be used.  Which is a bit over my head.  I've found evidence that this is correct from the following.

Here's my initialization code for one of the forms:

 OffsetX = 1920

            FixedHeight = 1080
            FixedWidth = 1920

            With FirstForm
                .StartPosition = FormStartPosition.Manual
                .FormBorderStyle = Windows.Forms.FormBorderStyle.None
                .Location = New Point(OffsetX, OffsetY)
                .Size = New Size(FixedWidth, FixedHeight)
                .BackColor = Color.Black
                .PictureBox1.Location = New Point(0, 0)
                .PictureBox1.Size = New Size(FixedWidth, FixedHeight)
                .PictureBox1.Image = Image.FromFile(initImage)
                .PictureBox1.SizeMode = PictureBoxSizeMode.Zoom

                FirstForm.Update()
                FirstForm.Show()
            End With

And here's the code for updating the image in the picturebox:

   With FirstForm
            j = 1
            PictureString = CurrentPic(j)
            .PictureBox1.Image.Dispose()
            .PictureBox1.Image = Image.FromFile(PictureString)
            .PictureBox1.Refresh()
            .Update()
            .Show()
        End With
        FirstForm.Refresh()
        FirstForm.Show()

Obviously I'm loading this with extra refreshes and shows to get the image to change every time it's called for.

The larger environment here has n forms, each with a picture box.  

I seem to have partially fooled the system by initializing FirstForm first in the sequence of forms, but updating it last in the list of forms.  If I hold to the same order, First....last from inititialization updating/refreshing sticks consistently for the first form and the image is updated to the current image 1 in 5 times. 

Here's where the really odd behavior shows up.  When the FirstForm is updated last, it works 4 of 5 times.  That fifth time the image may update, then flicker and the old image that was supposed to be disposed shows up instead.

So I'm guessing the commenter I referred to earlier was right, that I've wandered into something where I'm unknowingly working outside the threading/asynchronous/eventdriven system, and I need to do something differently.  Because I've seen this problem raised in 20-30 different contexts around the web, with no obvious answer, this might be something for a white paper from MS.

Thanks for any ideas!

ps...it seems to behave the same whether compiled or run under the VB.Net Express environment.

====

Another observation- The problems occur on Display2 , which on the display resolution screen is immediately adjacent to what windows Display 1- you're normal single monitor windows interface screen.  (My FirstForm above is aimed at Display 2)  When the system decides it's time to go into screen saver  mode it seems to take display 2 along with display 1.  I don't have a clue how to formally test that. 


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>