hello, I have created a panel (I inherit from the form panel) and a control. when i add the panel to a form the onpaint of the panel, which I override is called. in the onpaint function of my panel i create an instance of my control and i add it to the controls of the panel. in my contorl I also override the onpaint of the contorl but this time the on paint of my contorl is not called when i add it to the conrols property of the panel which i created. how can i call the onpaint of the control from the onpaint of the panel? thanks
You should not create a control in the OnPaint Method as it is called million times. Try creating the control in the OnCreateControl method because it will be called when the control is being created.
I am sorry but i did not understand. which control i need to create in OnCreateControl method and where do i override the OnCreateControl? the panel or the conrtol?
Instead of doing this in OnPaint you should be doing it in OnCreateControl. The OnPaint of which ever class you mentioned.
thank for your help. just for general knowledge i would like to know why the onpaint of the panel is called automatically when i add it to the controls of the form and the onpaint of the control does not work when i add it to the controls of the panel.
OnPaint is called whenever control need to be painted and so when you add the new control it needs re-painting.
thanks for your reply. if as you say when I add the new control it needs re-painting, then why the onpaint of the contorl is not called when i add it to the controls of the panel?
When the OnPaint will be called is totally dependent on the OS and you should read the documents about Windows Programming and Paint method use. Whenever windows think it needs the control to be painted it sends the Paint method. Your case could be that you are adding a control in one case its transparent and so parent is sent the paint method and other case its not transparent and so its not sent.
hello, I did as you said but I have encountered in another problem. when i create the panel the oncreatecontrol is called and all the controls are created and painted in the panel but when i create the panel again not all the controls are painted in the panel and only one is painted in the panel. can you tell me what is the problem?