您的位置:首页 > 其它

ToolStrip动态添加自定义控件

2008-11-06 23:36 225 查看
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);

}

列:

ToolStripControlHost toolStripControlHost = new ToolStripControlHost(new Button.DJGridSetButton());
//Button.DJGridSetButton djBtn = new ZF_ERP.Button.DJGridSetButton();
((Button.DJGridSetButton)toolStripControlHost.Control).GridID = m_FormID;
((Button.DJGridSetButton)toolStripControlHost.Control).FormID = m_FormID;
((Button.DJGridSetButton)toolStripControlHost.Control).Text = "单据表格设置";
toolStrip.Items.Add(toolStripControlHost);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: