Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   control onpaint does not work (http://www.go4expert.com/forums/control-onpaint-t6648/)

morfix78 2Oct2007 20:58

control onpaint does not work
 
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

shabbir 2Oct2007 21:45

Re: control onpaint does not work
 
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.

morfix78 2Oct2007 21:59

Re: control onpaint does not work
 
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?

shabbir 3Oct2007 04:04

Re: control onpaint does not work
 
Quote:

in the onpaint function of my panel i create an instance of my control and i add it to the controls of the panel.
Instead of doing this in OnPaint you should be doing it in OnCreateControl. The OnPaint of which ever class you mentioned.

morfix78 4Oct2007 12:32

Re: control onpaint does not work
 
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.

shabbir 4Oct2007 17:54

Re: control onpaint does not work
 
OnPaint is called whenever control need to be painted and so when you add the new control it needs re-painting.

morfix78 4Oct2007 22:12

Re: control onpaint does not work
 
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?

shabbir 5Oct2007 04:22

Re: control onpaint does not work
 
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.

morfix78 14Oct2007 19:26

Re: control onpaint does not work
 
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?

shabbir 14Oct2007 19:31

Re: control onpaint does not work
 
You InValidate the other panels when they need to be painted.


All times are GMT +5.5. The time now is 07:32.