, . , . , , , - ToolStripPanel, , ToolStrip OnLocationChanged ( LocationChanged, , d ToolStrip).
public class ToolStripEx : ToolStrip
{
protected override void OnLocationChanged(EventArgs e)
{
if (this.Location.Y >= this.Parent.MaximumSize.Height)
{
this.Location = new Point(this.Location.X, 0);
}
else
{
base.OnLocationChanged(e);
}
}
}
. ToolStrip , - , reset , , , .
, , ToolStrip , . , .
:
Windows Forms. ToolStripEx.cs , , :
Orientation
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public class ToolStripEx : ToolStrip
{
protected override void OnLocationChanged(EventArgs e)
{
if (this.Parent is ToolStripPanel)
{
ToolStripPanel parent = this.Parent as ToolStripPanel;
if (parent.Orientation == Orientation.Horizontal)
{
if (this.Location.Y != 0)
{
this.Location = new Point(this.Location.X, 0);
return;
}
}
else if (parent.Orientation == Orientation.Vertical)
{
if (this.Location.X != 0)
{
this.Location = new Point(0, this.Location.Y);
return;
}
}
}
base.OnLocationChanged(e);
}
}
}
, ToolStripEx .
ToolStripContainer , Dock Fill, ..
ToolStripEx ( cog) TopToolStripPanel. .
Form1.cs:
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.toolStripContainer1.TopToolStripPanel.MaximumSize = new Size(0, toolStripEx1.Height);
this.toolStripContainer1.LeftToolStripPanel.MaximumSize = new Size(toolStripEx1.Height, 0);
this.toolStripContainer1.BottomToolStripPanel.MaximumSize = new Size(0, toolStripEx1.Height);
this.toolStripContainer1.RightToolStripPanel.MaximumSize = new Size(toolStripEx1.Height, 0);
}
}
}
. ( , Orientation of Orientation.Vertical). , , else if parent.Orientation == Orientation.Vertical.
, . , ToolStripEx .
, ToolStrip , , .
- ToolStripContainer, ToolStripEx. , - ToolStrip, ToolStripEx.
- :
, , . ToolStripEx:
protected override void OnBeginDrag(EventArgs e)
{
}
, . , , , ToolStrip OnBeginDragDrop, ToolStrip , .