ToolStripControlHost.Control Propriété

Définition

Obtient le Control que ce ToolStripControlHost héberge.

[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control Control { get; }

Valeur de propriété

Control que ce ToolStripControlHost héberge.

Attributs

Exemples

L’exemple de code suivant illustre la construction d’un ToolStripControlHost contrôle et définit une propriété sur le contrôle encapsulé à l’aide de la Control propriété . Pour exécuter cet exemple, collez le code dans un formulaire qui contient un ToolStrip nommé toolStrip1 et un appel InitializeDateTimePickerHost à partir du constructeur du formulaire ou du Load gestionnaire d’événements.

ToolStripControlHost dateTimePickerHost;

private void InitializeDateTimePickerHost()
{

    // Create a new ToolStripControlHost, passing in a control.
    dateTimePickerHost = new ToolStripControlHost(new DateTimePicker());

    // Set the font on the ToolStripControlHost, this will affect the hosted control.
    dateTimePickerHost.Font = new Font("Arial", 7.0F, FontStyle.Italic);

    // Set the Width property, this will also affect the hosted control.
    dateTimePickerHost.Width = 100;
    dateTimePickerHost.DisplayStyle = ToolStripItemDisplayStyle.Text;

    // Setting the Text property requires a string that converts to a 
    // DateTime type since that is what the hosted control requires.
    dateTimePickerHost.Text = "12/23/2005";

    // Cast the Control property back to the original type to set a 
    // type-specific property.
    ((DateTimePicker)dateTimePickerHost.Control).Format = DateTimePickerFormat.Short;

    // Add the control host to the ToolStrip.
    toolStrip1.Items.Add(dateTimePickerHost);
}

S’applique à

Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9