Link to home
Start Free TrialLog in
Avatar of jdcoburn
jdcoburn

asked on

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?
Avatar of UnifiedIS
UnifiedIS

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.
Avatar of jdcoburn

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of UnifiedIS
UnifiedIS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.