Windows.Forms.Panel updating problem in C#

D

Dave Spencer

Hi All,

I have a panel (I'll call "drawing panel") in a scrollable panel ("window
panel").
I am drawing a top view or a front view of a simple rectangular object on
the inner drawing panel.
I provide the user a button to select top view or front view.
Each view requires a transformation and resizing of the drawing panel so
that the drawing is positioned correctly and the inner drawing panel is
sized properly within the outer window panel.

When the user clicks a button to change views the new graphic is drawn
correctly except that the transformation and sizing does not happen to the
drawing panel so the graphic is out of position and the size of the drawing
panel is not updated.
If I select the same button again it correctly updates the size and position
of the inner drawing panel and draws the graphic correctly.
I can also do anything that causes the size of the outer window panel to
change and the inner panel updates correctly.

I do a CreateGraphics on the inner drawing panel early in the program and I
do all of my drawing on the resulting Graphics object.
When the user hits one of the view buttons:

I do a .Transform on the Graphics object (just a translation and scale)
I set the ClientSize of the drawing panel to some new value
I Invalidate the drawing panel (the drawing itself happens in the Paint
event)

Liberal use of Invalidate, Refresh, and calling my Draw function directly
does not help.
Any ideas?

Thanks,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top