cannot draw graphics on panel

hi -- I have two panels that are added to a tab control that make up the primary division of my windows form application. The right hand panel (called graph_panel) will draw appropriately when a Graphics object is created, attached to the graph_panel. However, based on a parameter passed to the method, i want to add a child panel (programmatically), create a Graphics object, and put some lines in the child panel. when going into run, the child panel flickers briefly and then whatever is drawn disappears. Does anybody know what limitations there are to creating a child panel as a graphics container?
jdcoburnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UnifiedISCommented:
Is the child panel inside the graph_panel or is the child the left hand panel?  I would not be surprised if layering multiple panels would not display properly.  You might want to draw the panel (i.e. rectangle) instead of trying to layer two panels.
0
jdcoburnAuthor Commented:
hi --thanks for the comment. i finally got the child panel to work -- i had to call childPanel.Refresh() before i created teh graphics object to draw the line. any idea why that would be the case? it doesn't work if i call refresh after the graphics object is created. what is refresh actually doing?
thanks for any help.
Jim
0
UnifiedISCommented:
Not sure about refresh.  I haven't ever tried to create a panel and draw on it programmatically.  From what you described, I was thinking you could have a persistent child panel, and depending on the param in your draw method, call out childpanel.invalidate.  Then, in childpanel_paint event, call a method to draw on your child panel with childpanel.creategraphics passed as the graphics object.  

In case you haven't set these options, here are a couple gdi+ settings I've found helpful:

Put in the load event of the form

causes objects to repaint when the form is resized
Me.SetStyle(ControlStyles.ResizeRedraw, True)

I think this one smooths out the drawing process, less flickering
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jdcoburnAuthor Commented:
ok -- I suspect a lot of the problem is related to when and how the drawing takes place. I have the main panel.paint event wired to the original method, so that it re-calls the entire drawing process. this works fine for other controls. but it doesn't resize the programmatically added controls, even though i'm using the parent width property. the other anomoly is related to docking. if i programmatically dock, it doesn't work.
i'll try your recommendations and get back to you.
0
jdcoburnAuthor Commented:
in the for what it's worth category, I was able to solve the problem by using handles to the controls, which allowed me to explicitly control the drawing order and could be passed to the paint method.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.