Help Displaying & Stabilizing PictureBox Contents

T

The Confessor

(ellipses in place of code sections which do not deviate from defaults)

Private Sub Form_Main_Load(...) Handles MyBase.Load
For A = 0 To 16
For B = 0 To 14
PictureBox_MapEditor_Map.CreateGraphics.DrawImage
(System.Drawing.Image.FromFile("C:\The RPG Project\Test 2.bmp"), A * 40,
B * 40)
Next
Next
End Sub

First:

The preceeding code tiles a PictureBox with 17 Columns by 15 Rows of what
will eventually be varying graphics (as befits a Final Fantasy IV-style
visual presentation)...

At least it does in theory. In actuality, nothing happens unless I tie
the tiling to a post-Form.Load event.

But I'd *really* like it to execute absent at program start absent user
input. Any way to do this?

Second:

How do I stabilize the contents of the PictureBox, so it won't be
affected by alt/tabbing, moving a window on top of it, or other such
annoyances?

Third:

The PictureBox is contained (eventually with several other controls) in a
Panel. Is there any way that I can force references to the control to
also reference the panel, as in Panel.PictureBox.CreateGraphics?

Will this also allow me to have two same-named component controls in the
form, as long as they are members of different panels?

Thanks in advance for any assistance,

The Confessor
 
C

CMM

AFAIK the .NET picturebox doesn't have an autoredraw property but it's easy
to simulate:

Dim bmp As New Bitmap(width, height)
Dim gr As Graphics = Graphics.FromImage(bmp)
'draw as before
PictureBox_MapEditor_Map.Image = bmp

That works... but, personally, I don't see why not just put drawing code in
the PictureBox's Paint event. Drawing is extremely fast in .NET... and sorta
makes "autoredraw" obsolete.

P.S.
Oh yeah and I think you're supposed to do gr.Dispose() on manually created
gr objects... or else they'll go into garbage collection land still holding
on to GDI resources until the GC finally destroys it (whenever that is... if
ever).
 
Top