ToolStripControlHost.Control 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此 Control 所承载的 ToolStripControlHost。
public:
property System::Windows::Forms::Control ^ Control { System::Windows::Forms::Control ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control Control { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Control : System.Windows.Forms.Control
Public ReadOnly Property Control As Control
属性值
此 Control 所承载的 ToolStripControlHost。
- 属性
示例
下面的代码示例演示如何构造控件, ToolStripControlHost 并使用 Control 该属性在包装的控件上设置属性。 若要运行此示例,请将代码粘贴到包含 ToolStrip 来自窗体构造函数或事件处理程序的命名 toolStrip1
和调用 InitializeDateTimePickerHost
的 Load
窗体中。
ToolStripControlHost^ dateTimePickerHost;
void InitializeDateTimePickerHost()
{
// Create a new ToolStripControlHost, passing in a control.
dateTimePickerHost = gcnew ToolStripControlHost( gcnew DateTimePicker );
// Set the font on the ToolStripControlHost, this will affect the hosted control.
dateTimePickerHost->Font =
gcnew System::Drawing::Font( L"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 = L"12/23/2005";
// Cast the Control property back to the original type to set a
// type-specific property.
(dynamic_cast<DateTimePicker^>(dateTimePickerHost->Control))->Format =
DateTimePickerFormat::Short;
// Add the control host to the ToolStrip.
toolStrip1->Items->Add( dateTimePickerHost );
}
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);
}
Private dateTimePickerHost As ToolStripControlHost
Private Sub 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.
CType(dateTimePickerHost.Control, DateTimePicker).Format = DateTimePickerFormat.Short
' Add the control host to the ToolStrip.
toolStrip1.Items.Add(dateTimePickerHost)
End Sub