首页 新闻 会员 周边 捐助

WinForm开发

0
悬赏园豆:5 [已解决问题] 解决于 2012-01-13 16:51

请问大家,如何将进度条TrackBar 放进Menu里面呢?<<帮助>>那行是MenuStrip,<<速度>>那行是ToolStrip,可是ToolStrip里面没有TrackBar 控件,只有

这样该如何实现呢?

king2003的主页 king2003 | 初学一级 | 园豆:161
提问于:2012-01-13 10:03
< >
分享
最佳答案
0

In .NET there's a class named ToolStripControlHost which can be used to host custom controls or Windows Forms controls, in two ways:

Construct a ToolStripControlHost with a class that derives from Control. To fully access the hosted control and properties, you must cast the Control property back to the actual class it represents.

Extend ToolStripControlHost, and in the inherited class's default constructor, call the base class constructor passing a class that derives from Control. This option lets you wrap common control methods and properties for easy access in a ToolStrip.

The following sample demonstrates how to create a custom ToolStripTraceBarItem.

[ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip |
ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripTraceBarItem : ToolStripControlHost
{
public ToolStripTraceBarItem()
: base(new TrackBar())
{

}
}

After compiling, you'll find a ToolStripTraceBarItem in the drop down of the ToolStrip, select it from the drop down you'll be able to add a TraceBar to the ToolStrip.

 

http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx

看中间那段代码就行了,新建这样一个Class, 然后编译一下,就可以插进去这个类了

收获园豆:5
ChatinCode | 老鸟四级 |园豆:2272 | 2012-01-13 10:31

嗯,这个功能实现了,但界面外观不好看。

king2003 | 园豆:161 (初学一级) | 2012-01-13 16:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册