Windowless Controls Tutorial Part 1 - Continued

In my previous post, a reader mentioned that he was curious what happens to this tutorial when it is run a device that has a different form factor, or the screen is rotated. Well, the WindowlessControl system resizes and remeasures all its components of course!


But there's a problem, the image is scrolled off the screen! Let's fix that with a little code. Let's enable AutoScroll on "myHost" and then place a another VerticalStackPanelHost inside it that will then contain all the controls seen in this form. The myHost control will allow the new VerticalStackPanelHost to size vertically to whatever length it pleases, and show scroll bars automatically, as necessary. So, the modified constructor looks like this:

public HelloWorld()

// myHost is a Control that provides a transition from System.Windows.Forms to WindowlessControls.
// myHost.Control is the WindowlessControls.WindowlessControl that is "hosted" in the Windows.Windows.Forms.Control.
// put all the forms contents into a scrollHost, which will resize arbitrarily to fit its contents
VerticalStackPanelHost scrollHost = new VerticalStackPanelHost();
StackPanel stack = scrollHost.Control;
stack.HorizontalAlignment = WindowlessControls.HorizontalAlignment.Stretch;

// enable auto scrolling on myHost so if the contents (scrollHost) are too big, scroll bars appear
myHost.AutoScroll = true;



This form will now automatically set itself up properly and show scroll bars as necessary! Click here for the updated source code.