我有两个自定义工具条控件,可以为我提供NumericUpDown和TrackBar。这些用于控制和显示涂料应用中的画笔大小。 无论如何。当用户单击其中任何一个时,对作为子mdi窗口的绘制窗口的焦点将丢失。我原本以为父表单上的工具条控件不会从孩子那里获得焦点?这适用于标准工具条控件(按钮,标签等)。
以下是两个控件的代码:
的NumericUpDown
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
[
ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)
]
public class ToolStripNumericUpDownItem : ToolStripControlHost
{
public NumericUpDown numericUpDown;
public ToolStripNumericUpDownItem()
: base(new NumericUpDown())
{
numericUpDown = (NumericUpDown)this.Control;
numericUpDown.AutoSize = false;
numericUpDown.Maximum = 1000;
numericUpDown.Size = new Size(30, 20);
}
}
的TrackBar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
[
ToolStripItemDesignerAvailability
(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)
]
public class ToolStripTrackBarItem : ToolStripControlHost
{
public TrackBar trackBar;
public ToolStripTrackBarItem()
: base(new TrackBar())
{
trackBar = (TrackBar)this.Control;
trackBar.AutoSize = false;
trackBar.Maximum = 100;
trackBar.Size = new Size(200, 20);
trackBar.TickFrequency = 1;
trackBar.TickStyle = TickStyle.None;
}
}