Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IContainerControl Interface

Provides the functionality for a control to act as a parent for other controls.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public interface IContainerControl
public interface IContainerControl
public interface IContainerControl
Not applicable.

Notes to Implementers: Implement this interface in classes that you want to parent a collection of controls. The members of this interface allow you to activate a child control, or determine which control is currently active. When implemented in a class, ActivateControl takes a Control as a parameter and activates the specified control. The ActiveControl property activates or retrieves the control that is active. In most common scenarios, you do not need to directly implement this interface. For example, if you create a Windows Control Library project, Visual Studio generates an initial class for you. That class inherits from the UserControl class, and UserControl implements IContainerControl for you.

The following example inherits from the ScrollableControl class and implements the IContainerControl interface. Implementation is added to the ActiveControl property and the ActivateControl method.

using System;
using System.Windows.Forms;
using System.Drawing;

	public class MyContainer : ScrollableControl, IContainerControl
	{
		private Control activeControl;
		public MyContainer() 
		{
			// Make the container control Blue so it can be distinguished on the form.
			this.BackColor = Color.Blue;
			
			// Make the container scrollable.
			this.AutoScroll = true;
		}

		// Add implementation to the IContainerControl.ActiveControl property.
		public Control ActiveControl
		{
			get
			{
				return activeControl;
			}

			set
			{
				// Make sure the control is a member of the ControlCollection.
				if(this.Controls.Contains(value))
				{
					activeControl = value;
				}
			}
		}

		// Add implementations to the IContainerControl.ActivateControl(Control) method.
		public bool ActivateControl(Control active)
		{
			if(this.Controls.Contains(active))
			{
				// Select the control and scroll the control into view if needed.
				active.Select();
				this.ScrollControlIntoView(active);
				this.activeControl = active;
				return true;
			}
			return false;
		}
	}

import System.*;
import System.Windows.Forms.*;
import System.Drawing.*;

public class MyContainer extends ScrollableControl implements IContainerControl
{
    private Control activeControl;

    public MyContainer()
    {
        // Make the container control Blue so it can be 
        // distinguished on the form.
        this.set_BackColor(Color.get_Blue());

        // Make the container scrollable.
        this.set_AutoScroll(true);
    } //MyContainer

    // Add implementation to the IContainerControl.ActiveControl property.
    /** @property 
     */
    public Control get_ActiveControl()
    {
        return activeControl;
    } //get_ActiveControl

    /** @property 
     */
    public void set_ActiveControl(Control value)
    {
        // Make sure the control is a member of the ControlCollection.
        if (this.get_Controls().Contains(value)) {
            activeControl = value;
        }
    } //set_ActiveControl

    // Add implementations to the IContainerControl.
    // ActivateControl(Control) method.
    public boolean ActivateControl(Control active)
    {
        if (this.get_Controls().Contains(active)) {
            // Select the control and scroll the control into view if needed.
            active.Select();
            this.ScrollControlIntoView(active);
            this.activeControl = active;
            return true;
        }

        return false;
    } //ActivateControl
} //MyContainer

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.