在toolstripmenuitem中对对象进行分组 [英] Grouping objects in toolstripmenuitem
问题描述
我已使用以下代码向ToolStripMenuItem添加了一个NumericUpDown对象:
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public class objTSNumericUpDown:ToolStripControlHost
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public NumericUpDown objTSSpinner {get {return(NumericUpDown) this.Control; } $
public objTSNumericUpDown():base(new NumericUpDown()){}
public objTSNumericUpDown (string strName,Dictionary Drawing):base(new NumericUpDown())
{objTSSpinner.Value = 0;
objTSSpinner.Dock = DockStyle.None;
Dock = DockStyle.None;
objTSSpinner.Maximum = Drawing [MaxValue];
objTSSpinner.Minimum = Drawing [MinValue];
objTSSpinner.Location = new Point(Drawing [LocationX],Drawing [LocationY]);
objTSSpinner.Size = new Size(Drawing [SizeX],绘制[SizeY]);
尺寸=新尺寸(绘图[SizeX],绘图[SizeY]);
Name = strName;
TextChanged + = new EventHandler(Textchanged_UpDwn);
}
我在之前的ToolStripMenuItem中有一个Label。
我很想拥有Label p在同一个ToolStripMenuItem中撤消NumericUpDown。
实质上,两个对象都在同一条线上。提前致谢。
我的尝试:
我有尝试了多种不同的方法,包括向ToolStripMenuItem添加一个groupbox ......此时无济于事!
I have added a NumericUpDown object to a ToolStripMenuItem with this code:
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public class objTSNumericUpDown : ToolStripControlHost
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public NumericUpDown objTSSpinner { get { return (NumericUpDown)this.Control; } }
public objTSNumericUpDown() : base(new NumericUpDown()) { }
public objTSNumericUpDown(string strName, Dictionary Drawing) : base(new NumericUpDown())
{ objTSSpinner.Value = 0;
objTSSpinner.Dock = DockStyle.None;
Dock = DockStyle.None;
objTSSpinner.Maximum = Drawing["MaxValue"];
objTSSpinner.Minimum = Drawing["MinValue"];
objTSSpinner.Location = new Point(Drawing["LocationX"], Drawing["LocationY"]);
objTSSpinner.Size = new Size(Drawing["SizeX"], Drawing["SizeY"]);
Size = new Size(Drawing["SizeX"], Drawing["SizeY"]);
Name = strName;
TextChanged += new EventHandler(Textchanged_UpDwn);
}
I have a Label in the previous ToolStripMenuItem.
I would love to have the Label precede the NumericUpDown in the same ToolStripMenuItem.
In essence, have both objects on the same line. Thanks in advance.
What I have tried:
I have tried multiple different approaches to include adding a groupbox to the ToolStripMenuItem... to no avail at this point!
推荐答案
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip) ]
公共类objTSNUPGroupBox:ToolStripControlHost
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GroupBox objTSGroupBox {get {return(GroupBox)this.Control; } $
public objTSNUPGroupBox():base(new GroupBox()){}
public objTSNUPGroupBox (string strName,appEventArgs e,object ParentPanel,objToolStrip objTS):base(new GroupBox())
{
Control [] objects = new Control [2];
objects [0] = new objLabel(strName.Replace(grp,lbl),e.GetObjects [strName.Replace(grp,lbl)]);
objects [1] = new objNumericUpDown(strName.Replace(grp,nup),e.GetObjects [strName.Replace(grp,nup)]);
objTSGroupBox.Controls.AddRange(objects);
objTSGroupBox.Size = new Size(e.GetObjects [strName] [SizeX],e.GetObjects [strName] [SizeY]);
objTSGroupBox.Name = strName;
}
}
好的......这很有效。无法将ToolStripItems添加到GroupBox,我不得不在GroupBox中使用表单对象。我宁愿拥有一个完整的ToolStrip解决方案,而不是这个工作。任何有关此问题的建议和/或启示都将得到适当的赞赏。仍然不能得到我想要的GroupBox的大小,但我会继续研究它!
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public class objTSNUPGroupBox : ToolStripControlHost
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GroupBox objTSGroupBox { get { return (GroupBox)this.Control; } }
public objTSNUPGroupBox() : base(new GroupBox()) { }
public objTSNUPGroupBox(string strName, appEventArgs e, object ParentPanel, objToolStrip objTS) : base(new GroupBox())
{
Control[] objects = new Control[2];
objects[0] = new objLabel(strName.Replace("grp", "lbl"), e.GetObjects[strName.Replace("grp", "lbl")]);
objects[1] = new objNumericUpDown(strName.Replace("grp", "nup"), e.GetObjects[strName.Replace("grp", "nup")]);
objTSGroupBox.Controls.AddRange(objects);
objTSGroupBox.Size = new Size(e.GetObjects[strName]["SizeX"], e.GetObjects[strName]["SizeY"]);
objTSGroupBox.Name = strName;
}
}
Ok... this worked. Cannot add ToolStripItems to a GroupBox and I had to use form objects in the GroupBox. I would much rather have a complete ToolStrip solution as opposed to this work around. Any suggestions and/or enlightenment concerning this issue would be duly appreciated. Still can't get the size of the GroupBox what I want but I'll continue to research it!
这篇关于在toolstripmenuitem中对对象进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!