|
I found that if you modify a user control constructor then a usercontrol used before this modification won't be affected by those modification.
Here what i did: 1.I create a new windows form project. 2.In this project I create a second windows form project where i add a user control. The second project is built before the first project. 3.In the first project toolbox i add an item from the second project debug "exe" folder (to add the usercontrol i have just created) 4.I add the new usercontrol to the windows form of the first project On execution evething works fine 5.I modify the usercontrol constructer .Now It backColor is Wheat and almost half transparent public processusButton() { InitializeComponent(); this.BackColor = Color.FromArgb(100, Color.Wheat); //Add this line } 6.I add a second usercontrol to the first project windows form Now the first and second user control differ in the View Designer and on execution. The first usercontrol is not wheat and not half transparent but the second is.
7.But now if you put this modification in the Load event the two usercontrol will be the same.
So is this a bug or is it normal? Thanks
|
| Plum117 Friday, October 20, 2006 5:36 PM |
The form designer has overridden your user control's default backcolor that you set in the constructor because it is not the same as the default color as set in the framework. Click on the Show All Files icon in the Solution Explorer, open the node next to the form and double-click the Designer.cs file. Look at the code that initializes UserControl11, you should see an assignment to the BackColor property. Delete that statement and the control will assume the default background color.
|
| nobugz Friday, October 20, 2006 9:32 PM |
You need to tell the IDE that your 1st project depends on your 2nd project. Right click the 1st project in the Solution Explorer, Project Dependencies, select your 2nd project. This ensures your 2nd project gets build before the 1st and the 1st gets rebuilt if the 2nd changes.
|
| nobugz Friday, October 20, 2006 6:41 PM |
I've just try it and it doesn't work. Note that my problems is when I add the code in the CONSTRUCTER because if its in the load event fonction it works.
|
| Plum117 Friday, October 20, 2006 7:38 PM |
Understood. The forms designer executes the constructor. If you make changes to it, be sure to rebuild your project before continuing designing.
|
| nobugz Friday, October 20, 2006 8:32 PM |
Even if a rebuild my project, the usercontrol created before the modification is still not updated. Try the steps I wrote in my first post, you'll see it even if you rebuild, clean and rebuild. Also just to be sure, UserControl1() is the constructor in this code? I don't see why it shouldn't be but i ask!:
namespace usercontrol { public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); this.BackColor = Color.FromArgb(100, Color.Black); } } }
|
| Plum117 Friday, October 20, 2006 9:12 PM |
The form designer has overridden your user control's default backcolor that you set in the constructor because it is not the same as the default color as set in the framework. Click on the Show All Files icon in the Solution Explorer, open the node next to the form and double-click the Designer.cs file. Look at the code that initializes UserControl11, you should see an assignment to the BackColor property. Delete that statement and the control will assume the default background color.
|
| nobugz Friday, October 20, 2006 9:32 PM |
nobugz is correct.
This has something to do with IDE's way of propagating property changes across the projects. Any non-default property values of the UserControl will be added to the form's InitializeComponent which happens AFTER the usercontrol instantiation.
Remember when you drop the usercontrol on the form. The form's initialization sequence is in effect. |
| JRQ Friday, October 20, 2006 10:33 PM |