473,594 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ 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 ControlCollecti on 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 ControlCollecti on for them to work.
In my custom controls on paint method I loop through the Collection and add
them to the ControlCollecti on 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 .CollectionPreo perty.Add(myoth ercontrol);

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

protected void OnPaint(PaintEv entArgs pe){
foreach(MyCusto mControl in this.Collection Property){
this.Controls.A dd(MyCustomCont rol);
}
}
--------------------------------
I was thinking that in the set and get accessor for the Collection Property
I could just get and set directly to the ControlCollecti on
but it still seems like I am wrong in my organization and thinking on this.
Any Insights?
--
Ron Vecchi

Nov 15 '05 #1
5 3075

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.Control s.Add method does
many internal works.
So I think you should use the default ControlCollecti on 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 ControlCollecti on the OnPaint method is called.

I would like to use my Collection property but It seems that the controlsneed to be added to the ControlCollecti on for them to work.In my custom controls on paint method I loop through the Collection and addthem to the ControlCollecti on 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 exampleMyCustomContro l.CollectionPre operty.Add(myot hercontrol);

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

protected void OnPaint(PaintEv entArgs pe){
foreach(MyCusto mControl in this.Collection Property){
this.Controls.A dd(MyCustomCont rol);
}
}
--------------------------------
I was thinking that in the set and get accessor for the Collection PropertyI could just get and set directly to the ControlCollecti onbut 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.co m

""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
news:rl******** ******@cpmsftng xa07.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.Control s.Add method does
many internal works.
So I think you should use the default ControlCollecti on 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.c om> wrote in
message news:uJ******** ******@TK2MSFTN GP12.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.co m

""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
news:rl******** ******@cpmsftng xa07.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.Control s.Add method does
many internal works.
So I think you should use the default ControlCollecti on 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 controlcollecti on 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
6177
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 OnPaint . The recangle draws correct when i press the mouse, but when i release the mouse the background is not restored What should i do in the Onpaint to make sure the background (the form) is restored correctly ? This problem already keeps...
5
9581
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 OnPaint(PaintEventArgs e) {
4
5663
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 class's OnPaint & OnPaintBackground). My button has a shape of rectangle with rounded corners and is filled with gradient brush, where user specifies the gradient colors. The dilema I have now is how to paint the button when it's disabled (Enabled =...
4
1965
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 .. Protected Overrides Sub OnPaint(ByVal pe As
0
1508
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+). Understandably, all the small updates cause the OnPaint method to be called for the different Panel *and* for the containing Panel. However, I want all results to be displayed at once. In other words, how can I wait for all subpanels to be drawn, before...
4
4626
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 program is like so: static void Main() {
4
6005
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) - http://gidsfiles.googlepages.com/LinedTextBox_withText.jpg The text turns BOLD and the lines kinda get erased because of the text. perhaps i could overide or handle the onKeydown or somethin and intercept the text to be entered and then draw it myself. Any suggestions????????
1
3603
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), OnPaint is not getting called... Here is the relevent code: I'm trying to create a "rubber band" rectangle effect on my form. Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles...
2
2043
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 only half of the diagram is getting painted,some lines are missing in the diagram. private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { string str=listBox1.SelectedItem.ToString(); string str1=null;...
0
7947
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8255
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8010
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5413
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3868
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.