IContainerControl Interface
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Biedt de functionaliteit voor een besturingselement om als bovenliggend besturingselement te fungeren voor andere besturingselementen.
public interface class IContainerControl
public interface IContainerControl
type IContainerControl = interface
Public Interface IContainerControl
- Afgeleid
Voorbeelden
In het volgende voorbeeld wordt de ScrollableControl klasse overgenomen en wordt de IContainerControl interface geïmplementeerd. Implementatie wordt toegevoegd aan de ActiveControl eigenschap en de ActivateControl methode.
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;
}
};
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;
}
}
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
Notities voor uitvoerders
Implementeer deze interface in klassen die u boven een verzameling besturingselementen wilt plaatsen. Met de leden van deze interface kunt u een onderliggend besturingselement activeren of bepalen welk besturingselement momenteel actief is. Wanneer deze wordt geïmplementeerd in een klasse, ActivateControl(Control) wordt een Control parameter gebruikt en wordt het opgegeven besturingselement geactiveerd. De ActiveControl eigenschap activeert of haalt het besturingselement op dat actief is.
In de meest voorkomende scenario's hoeft u deze interface niet rechtstreeks te implementeren. Als u bijvoorbeeld een Windows Control Library-project maakt, Visual Studio een eerste klasse voor u genereert. Deze klasse neemt over van de UserControl klasse en UserControl implementeert IContainerControl voor u.
Eigenschappen
| Name | Description |
|---|---|
| ActiveControl |
Hiermee haalt u het besturingselement op dat actief is op het containerbeheer of stelt u het in. |
Methoden
| Name | Description |
|---|---|
| ActivateControl(Control) |
Hiermee activeert u een opgegeven besturingselement. |