Hi everyone,
I've got this problem when creating a new custom UserControl. In details, I create a derived UserControl with a DataGridView that has Anchor property set to [Left, Top, Right, Bottom] so that the DataGridView can resize whenever the UserControl container's sizes change. But when the application runs, the result is not exactly expected. The DataGridView right- and bottom-edge always grow outside the UserControl border. To understand this issue, I have debugged and discovered that whenever a UserControl is created, its size is always default to [100, 100] despite we set it to [800, 600] or anything else. I think this is the cause of the problem. When we design the UserControl, we use a larger size but in runtime, its size is default to [100, 100] so the automatic calculation of Anchor property becomes unexpected.
Can anyone give me some hint on how to solve this problem? I have one dirty solution but also sometimes malfunctions. My solution is that in UserControl's OnLoad event handler, I set the right and bottom-edge of child controls. This solution works fine for most of my custom UserControl but sometimes it makes me misunderstood. Sometimes the issue still happens. It makes me confused.
Can anyone give a clear explanation and a complete solution of this issue?
Thanks in advance