在 ToolStrip 中添加轨迹栏
我正在尝试在我的 ToolStrip 中添加一个 TrackBar。我在网上的某个地方找到了这段代码,但我不确定如何使用它,因为它可能应该被编译?
代码
/// <summary>
/// Adds trackbar to toolstrip stuff
/// </summary>
[
ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)
]
public class ToolStripTraceBarItem : ToolStripControlHost
{
public ToolStripTraceBarItem(): base(new TrackBar())
{
}
}
任何提示都会被采纳!
I am trying to add a TrackBar in my ToolStrip. I have found this code somewhere on the net but I am not sure how to use it as it should be compiled maybe?
Code
/// <summary>
/// Adds trackbar to toolstrip stuff
/// </summary>
[
ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)
]
public class ToolStripTraceBarItem : ToolStripControlHost
{
public ToolStripTraceBarItem(): base(new TrackBar())
{
}
}
Any tips will be appriciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需将此代码复制到表单源文件中即可。 (您还需要导入一些额外的内容,
using System.Windows.Forms.Design;
)。然后,当您尝试向工具条添加元素时,您将能够在设计器中看到
TraceBarItem
。要自定义 TraceBar,请将其添加到您发布的类的构造函数中:
TrackBar tb = (TrackBar)this.Control;
您可以使用该
tb
对象设置轨迹栏的所有属性。You can simply copy this code in your form source file. (You also need to import some extra stuff,
using System.Windows.Forms.Design;
).Then you'll be able to see
TraceBarItem
in the designer when you try to add an element to your toolstrip.To customize your TraceBar, add this to the constructor of the class you posted:
TrackBar tb = (TrackBar)this.Control;
You can set all the trackbar's properties using that
tb
object.