LayoutEngine Class
Provides the base class for implementing layout engines.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Use the LayoutEngine class when you want to create custom layout behavior at run time. Derive your own class from the LayoutEngine class and override the Layout method to define your custom layout behavior.
The following code example demonstrates the use of the LayoutEngine class to implement custom layout behavior.
Imports System Imports System.Collections.Generic Imports System.Drawing Imports System.Text Imports System.Windows.Forms Imports System.Windows.Forms.Layout ' This class demonstrates a simple custom layout panel. ' It overrides the LayoutEngine property of the Panel ' control to provide a custom layout engine. Public Class DemoFlowPanel Inherits Panel Private layoutEng As DemoFlowLayout Public Sub New() End Sub Public Overrides ReadOnly Property LayoutEngine() As LayoutEngine Get If layoutEng Is Nothing Then layoutEng = New DemoFlowLayout() End If Return layoutEng End Get End Property End Class ' This class demonstrates a simple custom layout engine. Public Class DemoFlowLayout Inherits LayoutEngine Public Overrides Function Layout( _ ByVal container As Object, _ ByVal layoutEventArgs As LayoutEventArgs) As Boolean Dim parent As Control = container ' Use DisplayRectangle so that parent.Padding is honored. Dim parentDisplayRectangle As Rectangle = parent.DisplayRectangle Dim nextControlLocation As Point = parentDisplayRectangle.Location Dim c As Control For Each c In parent.Controls ' Only apply layout to visible controls. If c.Visible <> True Then Continue For End If ' Respect the margin of the control: ' shift over the left and the top. nextControlLocation.Offset(c.Margin.Left, c.Margin.Top) ' Set the location of the control. c.Location = nextControlLocation ' Set the autosized controls to their ' autosized heights. If c.AutoSize Then c.Size = c.GetPreferredSize(parentDisplayRectangle.Size) End If ' Move X back to the display rectangle origin. nextControlLocation.X = parentDisplayRectangle.X ' Increment Y by the height of the control ' and the bottom margin. nextControlLocation.Y += c.Height + c.Margin.Bottom Next c ' Optional: Return whether or not the container's ' parent should perform layout as a result of this ' layout. Some layout engines return the value of ' the container's AutoSize property. Return False End Function End Class
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.