ContainerControl 类
为可用作其他控件的容器的控件提供焦点管理功能。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class ContainerControl
Inherits ScrollableControl
Implements IContainerControl
用法
Dim instance As ContainerControl
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class ContainerControl : ScrollableControl, IContainerControl
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class ContainerControl : public ScrollableControl, IContainerControl
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class ContainerControl extends ScrollableControl implements IContainerControl
ComVisibleAttribute(true)
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
public class ContainerControl extends ScrollableControl implements IContainerControl
备注
ContainerControl 表示可用作其他控件的容器的控件并提供焦点管理功能。从该类继承的控件可以跟踪它们包含的活动控件,即使焦点移动到不同容器内的某个位置。
ContainerControl 对象为包含的控件提供逻辑边界。容器控件可以捕获 Tab 键按下事件,并将焦点移动到集合中的下一个控件。
提示
容器控件不接收焦点;焦点总是设置在被包含控件构成的集合中的第一个子控件上。
通常不直接从 ContainerControl 类继承。Form、 UserControl 和 UpDownBase 类从 ContainerControl 继承。
示例
下面的代码示例从 ScrollableControl 类继承,并实现 IContainerControl 接口。将实现添加到 ActiveControl 属性和 ActivateControl 方法。
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Public Class MyContainerControl
Inherits ScrollableControl
Implements IContainerControl
Private myActiveControl As Control
Public Sub New()
' Make the container control Blue so it can be distinguished on the form.
Me.BackColor = Color.Blue
' Make the container scrollable.
Me.AutoScroll = True
End Sub
' Add implementation to the IContainerControl.ActiveControl property.
Public Property ActiveControl() As Control Implements IContainerControl.ActiveControl
Get
Return Me.myActiveControl
End Get
Set
' Make sure the control is a member of the ControlCollection.
If Me.Controls.Contains(value) Then
Me.myActiveControl = value
End If
End Set
End Property
' Add implementation to the IContainerControl.ActivateControl(Control) method.
public Function ActivateControl(active As Control) As Boolean Implements IContainerControl.ActivateControl
If Me.Controls.Contains(active) Then
' Select the control and scroll the control into view if needed.
active.Select()
Me.ScrollControlIntoView(active)
Me.myActiveControl = active
Return True
End If
Return False
End Function
End Class
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;
}
}
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
public ref class MyContainer: public ScrollableControl, public 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;
}
property Control^ ActiveControl
{
// Add implementation to the IContainerControl.ActiveControl property.
virtual Control^ get()
{
return activeControl;
}
virtual void set( Control^ value )
{
// 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.
virtual 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
继承层次结构
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
派生类
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 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
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
ContainerControl 成员
System.Windows.Forms 命名空间
Form
UserControl
UpDownBase
IContainerControl
ScrollableControl