This documentation is archived and is not being maintained.
LayoutEngine Class
Visual Studio 2010
Provides the base class for implementing layout engines.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The LayoutEngine type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitLayout | Initializes the layout engine. |
![]() | Layout | Requests that the layout engine perform a layout operation. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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.
#using <System.Drawing.dll> #using <System.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Collections::Generic; using namespace System::Drawing; using namespace System::Text; using namespace System::Windows::Forms; using namespace System::Windows::Forms::Layout; // This class demonstrates a simple custom layout engine. public ref class DemoFlowLayout : public LayoutEngine { public: virtual bool Layout(Object^ container, LayoutEventArgs^ layoutEventArgs) override { Control^ parent = nullptr; try { parent = (Control ^) container; } catch (InvalidCastException^ ex) { throw gcnew ArgumentException( "The parameter 'container' must be a control", "container", ex); } // Use DisplayRectangle so that parent.Padding is honored. Rectangle parentDisplayRectangle = parent->DisplayRectangle; Point nextControlLocation = parentDisplayRectangle.Location; for each (Control^ currentControl in parent->Controls) { // Only apply layout to visible controls. if (!currentControl->Visible) { continue; } // Respect the margin of the control: // shift over the left and the top. nextControlLocation.Offset(currentControl->Margin.Left, currentControl->Margin.Top); // Set the location of the control. currentControl->Location = nextControlLocation; // Set the autosized controls to their // autosized heights. if (currentControl->AutoSize) { currentControl->Size = currentControl->GetPreferredSize( parentDisplayRectangle.Size); } // 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 += currentControl->Height + currentControl->Margin.Bottom; } // 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; } }; // This class demonstrates a simple custom layout panel. // It overrides the LayoutEngine property of the Panel // control to provide a custom layout engine. public ref class DemoFlowPanel : public Panel { private: DemoFlowLayout^ layoutEngine; public: DemoFlowPanel() { layoutEngine = gcnew DemoFlowLayout(); } public: virtual property System::Windows::Forms::Layout::LayoutEngine^ LayoutEngine { System::Windows::Forms::Layout::LayoutEngine^ get() override { if (layoutEngine == nullptr) { layoutEngine = gcnew DemoFlowLayout(); } return layoutEngine; } } };
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show:
