Woodie said:
Thanks Armin, that helped a lot. I've got it working fine except for when
the form containing the picturebox is first shown. The picturebox is blank
when it's first shown, but then shows the calendar grid (it's going to be a
calendar program) only after resizing the form. The form is the project's
startup form. Here's my code, it's in a class that's instantiated in the
form's declaration section.
Public Sub Draw() Handles CalendarPictureBox.Paint,
CalendarPictureBox.Resize
I must admit, I did not know that this even can be compiled because the
signature for the Paint event handler is actually:
Public Sub Draw(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles
CalendarPictureBox.Paint
Then use
Dim G As Graphics = e.Graphics
to paint on. Do not call CalendarPictureBox.CreateGraphics. Otherwise
you paint on the picturebox first, afterwards it's covered by what
you've painted on e.graphics - i.e. by nothing (or by what's painted in
OnPaintBackground, the BackgroundColor). The reason why this does
not happen if you enlarge the control, is, that e.graphics contains a
clipping region covering only the dirty part (the "update region") of
the control. So if you enlarge it, the part already visible before is
not overwritten. In other words, the first time it is shown, the whole
control must be painted, and consequently the whole control is filled
with the background color.
Also, do _not_ call e.graphics.Dispose which would have been necessary
as ther counterpart to CreateGraphics.
The Resize event must be handled seperately because signatures do not
match. Call CalendarPictureBox.Invalidate there. That puts the whole
control's client area to the update region and it will be painted ASAP,
i.e. the Paint event will be raised.
BTW, Option Strict On is your friend.
WidthIndex = PictureBox1.Width / 7
Did you think about the fractions of this division? Cut? Rounding? Also
note that there is the \ operator (if required).
Armin