Click here to Skip to main content
15,886,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted
Updated 17-Oct-18 3:11am
v2

1 solution

[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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900