Another controls that inherit from the ScrollControl (described in a previous part of this series) is the ScrollPanel control. As the name implies, this is a panel that implement modern features like soft (kinetics) scrolling, and the design and functionality was inspired by the scroll view control on iPhone.
The ScrollPanel itself does not implement much logic, it mainly functions as a way for the app to implement a scrolling panel. In the TouchUI sample app, that is done in the DetailScrollPanel that inherits from ScrollPanel (and in turn from ScrollControl). The painting of the panel is done like this:
public override void Paint(Graphics g)
{
base.Paint(g);
imageHeight = Rectangle.Width * image.Size.Height / image.Size.Width;
g.DrawImage(imagenew Rectangle(Rectangle.Left,
Rectangle.Top + ScrollTop, Rectangle.Width, imageHeight),
new Rectangle(0, 0, image.Width, image.Height),
GraphicsUnit.Pixel);
string s = "Lorem ipsum dolor sit amet, consectetur adipisicing...";
g.DrawString(s, Common.Instance.Font, Common.Instance.FontBrush,
new RectangleF(Rectangle.Left + 8 * ScreenFactor,
Rectangle.Top + ScrollTop + imageHeight + 8,
Rectangle.Width - 16 * ScreenFactor,
ScrollHeight - imageHeight - 16 * ScreenFactor),
new StringFormat());
}
It draws the image at the top, and some Latin text as the bottom, and note that the use of the control's placement and size (Rectangle) will make both the image and the test resize with the screen. Dynamically that useful when switching between portrait and landscape, but it also means that different resolutions on different devices are handled.
This simple setup provides for full controls while still allowing for any use of the panel area. It could be of any height, and it could include any number of items. Although not included in the sample, it could also include traditional WinForms controls to allow input (text and combo boxes).