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?
 
UnifiedISConnect With a Mentor Commented:
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.