473,465 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3065

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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.