472,958 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 3036

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
5
by: christian ternek | last post by:
Hello ! I want to make a custom textbox and inherit a custom control from textbox. Now i want to change the looking of the textbox with the following code: protected override void...
4
by: | last post by:
Please, help. I created my contol, ButtonX, which subclasses System.Forms.Windows.Button class. I am doing my own paiting, by overriding OnPaint and OnPaintBackground (without calling base...
4
by: dominique | last post by:
Hi, In windows forms (vb.net), i use my own controls subclassed from base controls and i override the Onxxx methods. for example: Public Class MyBouton Inherits System.Windows.Forms.Button...
0
by: SirThanxALot | last post by:
Dear all, This prblem is bothering me quite some time now... I have a Panel with a custom panels on top of iet on top of it. Now I need do perform some updates on all of the (15+)....
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
4
by: giddy | last post by:
hi when i run this class i made here , this is what it looks like without text - http://gidsfiles.googlepages.com/LinedTextBox_1.jpg WITH TEXT (heres the issue) -...
1
by: sean | last post by:
I'm trying to create "rubber-band" rectangles by overriding the OnPaint method to place rectangles on top of all graphic controls, but when I call Me.Invalidate() (when the user moves the mouse),...
2
by: hgarg | last post by:
The onpaint() is getting called before calculating the required parameters by listBox1_SelectedIndexChanged function. I tried calling it at the end of this function. But of no use. Due to this issue...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.