Lupusregina Beta
Control getting resized when adding to FlowLayoutPanel
Hi. I have a weird problem. I have a FLP and I'm adding controls to it. I have four UserControl classes, each is 865 wide. Three of them are fine when I add, but when I add CtrlImage usercontrol it goes to 1298 wide. In trying to nail it down, I've removed all code from the class so it isn't doing anything crazy. It just has a single label and picturebox. I determined when it happens:
Control ctrl = col.GetControl();
MessageBox.Show("1: " + ctrl.Width.ToString());
record.Controls.Add(ctrl);
MessageBox.Show("2: " + ctrl.Width.ToString());
When I run this, I get "1: 865" and "2: 1298". What the heck happens when you add a control to a FLP that would cause it to expand? I tried asking GPT, it suggested I set AutoSize false and Dock to none on ctrl and WrapContents to true on the FLP. None of that made any difference. The only fix is to do ctrl.Width = 865 after I've added it.
I suppose that resolves it, but I really don't like not knowing why that happened and I'm sure this "band aid" is not a real fix. Anyone know what may cause this?
Thanks!
4 replies