Dynamically Adding Controls ... and their ZOrder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top