471,122 Members | 1,098 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

getting OnPaint to fire

I have a custyom control that has a property which wraps a collection. When
I add controls to the collection the OnPaint method of these newly added
controls never get fired.
But if I take the controls in the collection and add them to the custom
controls ControlCollection the OnPaint method is called.

I would like to use my Collection property but It seems that the controls
need to be added to the ControlCollection for them to work.
In my custom controls on paint method I loop through the Collection and add
them to the ControlCollection so the OnPaint will be called.

I'm pretty new to this, just wondering if this is an ass backwards way to
do this. Seems like it is and that I am missing something.
--------------------------------------

// myothercontrol OnPaint is never called from below example
MyCustomControl.CollectionPreoperty.Add(myothercon trol);

------------------------------------------------
////
// MyCustomControl OnPaint Method
// OnPaint menthod will get fired by using below example.
//

protected void OnPaint(PaintEventArgs pe){
foreach(MyCustomControl in this.CollectionProperty){
this.Controls.Add(MyCustomControl);
}
}
--------------------------------
I was thinking that in the set and get accessor for the Collection Property
I could just get and set directly to the ControlCollection
but it still seems like I am wrong in my organization and thinking on this.
Any Insights?
--
Ron Vecchi

Nov 15 '05 #1
5 2957

Hi Ron,

Thanks for posting in this group.
Based on my understanding, you find that the only the custom control's
Controls.Add method can make the child controls OnPaint method gets called.
I think this is by the design of .Net, Control.Controls.Add method does
many internal works.
So I think you should use the default ControlCollection of your custom
control.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2
Oops, I clicked new post.

See my post titled "Why Not Both?"

Charlie
-----Original Message-----
I have a custyom control that has a property which wraps a collection. WhenI add controls to the collection the OnPaint method of these newly addedcontrols never get fired.
But if I take the controls in the collection and add them to the customcontrols ControlCollection the OnPaint method is called.

I would like to use my Collection property but It seems that the controlsneed to be added to the ControlCollection for them to work.In my custom controls on paint method I loop through the Collection and addthem to the ControlCollection so the OnPaint will be called.
I'm pretty new to this, just wondering if this is an ass backwards way todo this. Seems like it is and that I am missing something.--------------------------------------

// myothercontrol OnPaint is never called from below exampleMyCustomControl.CollectionPreoperty.Add(myotherco ntrol);

------------------------------------------------
////
// MyCustomControl OnPaint Method
// OnPaint menthod will get fired by using below example.
//

protected void OnPaint(PaintEventArgs pe){
foreach(MyCustomControl in this.CollectionProperty){
this.Controls.Add(MyCustomControl);
}
}
--------------------------------
I was thinking that in the set and get accessor for the Collection PropertyI could just get and set directly to the ControlCollectionbut it still seems like I am wrong in my organization and thinking on this.

Any Insights?
--
Ron Vecchi

.

Nov 15 '05 #3
Jeffrey,

I am curious, couldn't the original poster just call Invalidate on the
parent hosting the controls, which will in turn cause the parent and the
child controls (including the ones just added) to repaint correctly?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:rl**************@cpmsftngxa07.phx.gbl...

Hi Ron,

Thanks for posting in this group.
Based on my understanding, you find that the only the custom control's
Controls.Add method can make the child controls OnPaint method gets called. I think this is by the design of .Net, Control.Controls.Add method does
many internal works.
So I think you should use the default ControlCollection of your custom
control.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4
As long as the custom control's onPaint is properly overriden, Invalidate()
should do exactly what you're looking for Ron.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uJ**************@TK2MSFTNGP12.phx.gbl...
Jeffrey,

I am curious, couldn't the original poster just call Invalidate on the
parent hosting the controls, which will in turn cause the parent and the
child controls (including the ones just added) to repaint correctly?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:rl**************@cpmsftngxa07.phx.gbl...

Hi Ron,

Thanks for posting in this group.
Based on my understanding, you find that the only the custom control's
Controls.Add method can make the child controls OnPaint method gets

called.
I think this is by the design of .Net, Control.Controls.Add method does
many internal works.
So I think you should use the default ControlCollection of your custom
control.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 15 '05 #5

Hi Nicholas,

Yes, Invalidate method will explicit force the control to repaint. So you
can also do this instead.
But I think the control's default controlcollection property is more
convinient to use. And it should meet your need.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Sagaert Johan | last post: by
5 posts views Thread by christian ternek | last post: by
4 posts views Thread by dominique | last post: by
reply views Thread by SirThanxALot | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.