Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a C# user control comprising three text boxes and some labels. It is designed to be laid out in either landscape fashion with the three text boxes and their labels laid out horizontally left-right next to each other, or in portrait mode with them above each other vertically. So I have a SizeChanged EventHandler which works well at run time - i.e. you can resize the form containing the user control and if the width is larger than the height it lays out horizontally, otherwise it lays out vertically. This works very well.

Now when I place the user control in VS Studio designer (Community 2015 edition) it does not initially lay out according to its resized dimensions. But if I subsequently resize it in VS designer, it does - obviously the SizeChanged EventHandler is being fired and correctly behaves. If I save that form and re-open it, it does not layout correctly again.

What do I have to do to get it to layout correctly when it is first placed or re-opened in VS designer?

What I have tried:

I have tried adding a call to the SizeChanged EventHandler in the User Control's Load Event handler and also in the host Form's Load Event handler but that doesn't solve the problem.
Posted
Updated 10-Jul-16 7:13am
v2
Comments
[no name] 10-Jul-16 13:51pm    
Maybe you have also to adjust the layout in something like "OnCreateControl" or "OnHandleCreated" or whatever fits.

Most probably "protected virtual void InitLayout()"
Richard MacCutchan 10-Jul-16 16:27pm    
You need to understand that event handlers do not get actioned in Visual Studio, but only when the compiled application is running.
Richard MacCutchan 11-Jul-16 4:58am    
Never happened with any of my forms.
[no name] 11-Jul-16 5:38am    
That is right. It does not happen for form events, but for your own controls derived from Control or e.g. Panel.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900