Class LayoutItemBase
Represents a non-control based layout component.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Windows.Forms.Tools
Assembly: Syncfusion.Shared.Base.dll
Syntax
public abstract class LayoutItemBase : IProvideLayoutInformation
Remarks
Derive your non-control based components from this class if you want them to participate in the layout management.
You can add such components to the manager using the same methods as the control derived classes. You can pass a LayoutItemBase derived class to any method that expects a control type argument since the LayoutItemBase has an implicit type-conversion operator that can convert itself to a control. In VB, use the ToControl() method to convert this instance to a control.
In your derived class, you can find out the size set by the layout manager through the Bounds property and the visibility through the Visible property (listening for the BoundsChanged event should also help). You should also provide the preferred size and minimum size of your component through the PreferredSize and MinimumSize overrides.
Examples
This first example shows a sample LayoutItemBase derived class:
public class MyRectangle : LayoutItemBase
{
public static Size PrefSize = new Size(0, 0);
protected Control parent;
protected Color color;
protected string text;
public MyRectangle(Control parent, Color color, string text)
{
this.parent = parent;
this.color = color;
this.text = text;
}
public void OnPaint( PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(color), this.Bounds);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
RectangleF r = new RectangleF(Bounds.Left, Bounds.Top,
Bounds.Width, Bounds.Height);
e.Graphics.DrawString(text, Control.DefaultFont, SystemBrushes.ControlText, r, sf);
}
// This override is a good place to repaint.
// Or you can listen to BoundsChanged event in LayoutItemBase.
protected override void OnBoundsChanged()
{
parent.Invalidate(new Rectangle(0, 0, this.parent.Width, this.parent.Height));
}
public override System.Drawing.Size MinimumSize
{
get { return MyRectangle.PrefSize; }
}
public override System.Drawing.Size PreferredSize
{
get
{
return MyRectangle.PrefSize;
}
}
}
The above class can then participate in layout as follows. The example assumes that there is a GridBagLayout manager that is already bound to a container.
private void Form1_Load(object sender, System.EventArgs e)
{
this.SuspendLayout();
// Current layout manager (Update every time you change the manager)
// Layout Component 1:
this.myRect1 = new MyRectangle(this.gridBagLayout1.ContainerControl, Color.FromArgb(133, 191, 117), "Paint Area 1");
this.myRect1.Bounds = new Rectangle(10, 10, 80, 20);
this.myRect1.Visible = true;
// Layout Component 2:
this.myRect2 = new MyRectangle(this.gridBagLayout1.ContainerControl, Color.FromArgb(222, 100, 19), "Paint Area 2");
this.myRect2.Bounds = new Rectangle(10, 40, 80, 20);
this.myRect2.Visible = true;
// Layout Component 3:
this.myRect3 = new MyRectangle(this.gridBagLayout1.ContainerControl, Color.FromArgb(196, 214, 233), "Paint Area 3");
this.myRect3.Bounds = new Rectangle(10, 70, 80, 20);
this.myRect3.Visible = true;
// Sample GridBagConstraints:
GridBagConstraints gbc1 = new GridBagConstraints();
GridBagConstraints gbc2 = new GridBagConstraints();
GridBagConstraints gbc3 = new GridBagConstraints();
gbc1.Fill = FillType.Both;
gbc1.WeightX = 0.2;
gbc1.WeightY = 0.5;
gbc1.GridPosX = 0;
gbc1.GridPosY = 0;
gbc2.Fill = FillType.Both;
gbc2.WeightX = 0.2;
gbc2.WeightY = 0.5;
gbc2.GridPosX = 1;
gbc2.GridPosY = 0;
gbc3.Fill = FillType.Both;
gbc3.WeightX = 0.4;
gbc3.WeightY = 0.5;
gbc3.GridPosX = 0;
gbc3.GridPosY = 1;
gbc3.CellSpanX = 2;
// Add all the components that are to participate in Layout Management.
// For GridBagLayouts pass gbcs for GridBagLayouts:
this.gridBagLayout1.SetConstraints(this.myRect1.ToControl(), gbc1);
this.gridBagLayout1.SetConstraints(this.myRect2.ToControl(), gbc2);
this.gridBagLayout1.SetConstraints(this.myRect3.ToControl(), gbc3);
this.ResumeLayout(true);
}</code></pre>
Constructors
LayoutItemBase()
Creates an instance of the LayoutItemBase.
Declaration
protected LayoutItemBase()
Fields
boundsChangingFromOutsideFramework
Declaration
protected bool boundsChangingFromOutsideFramework
Field Value
Type |
---|
System.Boolean |
Properties
Bounds
Gets / sets the bounds of the component in the corresponding layout manager's ContainerControl's client co-ordinates.
Declaration
public Rectangle Bounds { get; set; }
Property Value
Type | Description |
---|---|
System.Drawing.Rectangle | The rectangle within the parent control, in client co-ordinates. |
LayoutManager
Declaration
protected LayoutManager LayoutManager { set; }
Property Value
Type |
---|
LayoutManager |
MinimumSize
Returns the minimum size of the component.
Declaration
public abstract Size MinimumSize { get; }
Property Value
Type |
---|
System.Drawing.Size |
PreferredSize
Returns the preferred size of the component.
Declaration
public abstract Size PreferredSize { get; }
Property Value
Type |
---|
System.Drawing.Size |
Visible
Indicates whether the component should be drawn visible.
Declaration
public bool Visible { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True for visible; False for hidden. |
Methods
Control_BoundsChanged(Object, EventArgs)
Declaration
public void Control_BoundsChanged(object sender, EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | |
System.EventArgs | e |
OnBoundsChanged()
Declaration
protected virtual void OnBoundsChanged()
ToControl()
Returns the place holder control corresponding to this LayoutItemBase that lets the LayoutItemBase participate in the LayoutManager framework.
Declaration
public Control ToControl()
Returns
Type | Description |
---|---|
System.Windows.Forms.Control | The corresponding place holder control. |
Events
BoundsChanged
Called when the Bounds property changes.
Declaration
public event EventHandler BoundsChanged
Event Type
Type |
---|
System.EventHandler |
Operators
Implicit(LayoutItemBase to Control)
Returns the place holder control corresponding to the LayoutItemBase that lets the LayoutItemBase participate in the LayoutManager framework.
Declaration
public static implicit operator Control(LayoutItemBase lm)
Parameters
Type | Name | Description |
---|---|---|
LayoutItemBase | lm | The LayoutItemBase object. |
Returns
Type | Description |
---|---|
System.Windows.Forms.Control | The corresponding place holder control. |