469,935 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

Dynamically Adding Controls ... and their ZOrder

I'm trying to dynamically add some controls onto a Tab page and am
encountering a strange phenomenon that I'd like to get some feedback on.
Here's the guts of the code that I'm using:

Button newButton = new Button();

this.Controls.Add(newButton);

newButton.Parent = tabPageSummary;
newButton.BringToFront();
The above code works fine! BUT it took me awhile to learn that I HAD TO
have the last two lines AFTER the Controls.Add statement. I can somewhat
understand why the BringToFront statement has to be where it is but why does
the .Parent statement NEED to be AFTER the Add statement?

FYI if it's BEFORE it then the control's ZOrder sits in front of everything
on the form. So for example, even if I change tabs, the controls still
appears.

Just wondering why this is,

Robert W.
Vancouver, BC
Nov 17 '05 #1
1 5995
Hello,
What did you actually want? Did you want the button on the tabpage? if
yes, then you should have done tabpage.Controls.Add(button)..
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Donald Xie | last post: by
1 post views Thread by C Downey | last post: by
9 posts views Thread by Chris | last post: by
5 posts views Thread by Nathan Sokalski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.