Index of Button
-
Hi, I have a panel and inside that panel there are 3 buttons which I have put them drag and drop inside that panel, now I add dynamically button4 inside panel which it's left is left of button3+button3.width, so when i want to check first index of controls inside panel then i get button which i added dinamically, instead of button4 i except to get button1. So why i am getting this dinamically added button as first button of panel and i dont get button1 as first button inside panel? Can anyone explain me this? Best regards.
-
Hi, I have a panel and inside that panel there are 3 buttons which I have put them drag and drop inside that panel, now I add dynamically button4 inside panel which it's left is left of button3+button3.width, so when i want to check first index of controls inside panel then i get button which i added dinamically, instead of button4 i except to get button1. So why i am getting this dinamically added button as first button of panel and i dont get button1 as first button inside panel? Can anyone explain me this? Best regards.
At design-time: When you drag-drop Controls onto a Form, or into a container Control, like a Panel, they are written into the Designer.cs file in the order put on the Form. When the WinForm "engine" lays out the Controls, then the last one created is effectively "in front of" the other Controls. The ControlsCollection of a Form, or other container Control, is ordered by the z-order: so the last Control added, which is in front, is first. If you change the z-order of a Control at design-time, its order in the ControlsCollection changes. Use 'BringToFront() it goes to the start of the ControlsCollection; use 'SendToBack(), and it goes to the end. You can observe what happens at design-time by opening the Designer.cs file and examining the place in the file where Controls are added: change the z-order of one of the Controls you've put on the Form, and look at how the Designer.cs file has changed. At run-time: Controls you create and add to a Form, or container Control, are added to the end of the ControlsCollection of their container. If you use 'BringToFront() on a dynamically created Control before you add it to the ControlsCollection of a container, it will have no effect, but will not cause an error. If you use 'BringToFront() on a dynamically created Control after you add it to the ControlsCollection of a container, the Control will be at the 0th. element of the ControlsCollection.
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview