标签: toolstripcontrolhost

在ToolStrip中添加TrackBar

我想在ToolStrip中添加一个TrackBar.我在网上的某个地方发现了这个代码,但我不知道如何使用它,因为它应该编译?

    /// <summary>
    /// Adds trackbar to toolstrip stuff
    /// </summary>
    [
    ToolStripItemDesignerAvailability
        (ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)
    ]

    public class ToolStripTraceBarItem : ToolStripControlHost
    {
        public ToolStripTraceBarItem(): base(new TrackBar())
        {
        }
    }
Run Code Online (Sandbox Code Playgroud)

任何提示都会受到关注!

c# toolstrip trackbar toolstripcontrolhost

6
推荐指数
1
解决办法
4562
查看次数

带有自定义 ToolStripControlHost 的 ToolStrip 使 Tab 键顺序焦点变得奇怪

我正在经历一些奇怪的行为。让我试着解释一下,我将代码精简到最低限度,但问题仍然存在。所以首先,我使用 VS2013 和 .NET 4.0,我使用的是 Windows 8.1。

所以我有一个自定义UserControlTextBox多数民众赞成正在通过使用ToolStripControlHost,如果我专注于这个文本框和命中TAB通过控制这个文本框的左侧,它只是个周期。如果我将它聚焦并点击SHIFT+ TAB,它会在它右侧的按钮之间循环。

在此处输入图片说明

所以这是我的表格的一个例子。中间的文本框是一个自定义控件。我的代码(尽可能简化)如下所示:

[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripTestControl : ToolStripControlHost
{
    public ToolStripTestControl() : this(new TestControl()) { }
    public ToolStripTestControl(Control c) : base(c) { }
}

public class TestControl : UserControl
{
    private TextBox _textBox = new TextBox();

    public TestControl()
    {
        _textBox.Dock = DockStyle.Fill;
        this.Controls.Add(_textBox);
    }

    protected override Size DefaultMinimumSize { get { return new Size(100, 22); } }
}
Run Code Online (Sandbox Code Playgroud)

只需创建一个新的 …

c# winforms toolstripcontrolhost

3
推荐指数
1
解决办法
2282
查看次数

在下拉菜单中显示 ToolStripControlHost 的图像

我有一个 ToolStripSplitButton,下拉列表中包含各种元素。其中之一是包含在 ToolStripControlHost 中的 Trackbar,称为 ToolStripTrackbarItem。它的代码(我从 stackoverflow 得到的):

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace Application
{
    [System.ComponentModel.DesignerCategory("code")]
    [System.Windows.Forms.Design.ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ContextMenuStrip | ToolStripItemDesignerAvailability.MenuStrip)]

    public class ToolStripTrackbarItem : ToolStripControlHost
    {
        public ToolStripTrackbarItem()
            : base(CreateControlInstance())
        {
            this.Size = Control.Size;
        }
        public TrackBar TrackBar
        {
            get { return Control as TrackBar; }
        }
        private static Control CreateControlInstance()
        {
            TrackBar t = new TrackBar();
            t.AutoSize = false;
            return t;
        }
        [DefaultValue(0)]
        public int Value
        {
            get { return TrackBar.Value; }
            set { …
Run Code Online (Sandbox Code Playgroud)

.net c# toolstrip winforms toolstripcontrolhost

3
推荐指数
1
解决办法
1158
查看次数

为什么这个ToolStripControlHost不起作用?

我试图模仿这个答案但是虽然这有效:

public class TrackBarMenuItem : ToolStripControlHost
{
    TrackBar trackBar;
    public TrackBarMenuItem()
        : base(new TrackBar())
    {
        trackBar = Control as TrackBar;
    }
}
Run Code Online (Sandbox Code Playgroud)

这不是:

public class PanelMenuItem : ToolStripControlHost
{
    Panel panel;
    public PanelMenuItem()
        : base(new Panel())
    {
        panel = Control as Panel;
        Visible = true;
        Enabled = true;
        panel.AutoSize = false;
        panel.Size = new Size(100, 50);
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么?

我这样叫他们:

contextMenuStrip1.Items.Add(new TrackBarMenuItem());
contextMenuStrip1.Items.Add(new PanelMenuItem());
Run Code Online (Sandbox Code Playgroud)

c# winforms toolstripcontrolhost

2
推荐指数
1
解决办法
3098
查看次数

标签 统计

c# ×4

toolstripcontrolhost ×4

winforms ×3

toolstrip ×2

.net ×1

trackbar ×1