Windows Develop Bookmark and Share   
 index > Windows Forms General > Distance between ToolStrip controls
 

Distance between ToolStrip controls

Hello

I am trying to find out a method to keepa certain distance between ToolStrip controlsin the ToolStripPanel control.

I don't know how to do it.

Typin  Tuesday, April 22, 2008 2:24 PM

Hi,

I think it is feasible to add some spaces between two ToolStripControls. You can add a ToolStripLabel and set it's ToolStripText property to an empty string. Edit the Size property of the control to customize the width of the white space.

Regards,

Jacob

Jacob Sui - MSFT  Friday, April 25, 2008 8:01 AM

What about to override the LayoutEngine property of ToolStripPanel which contains the ToolStrip controls?

I overrided the LayoutEngine property of ToolStripPanel as below:

But the MyToolStripPanel control's layoutdoesn't work as ToolStripPanel. TheToolStrip controlsin MyToolStripPanel disappear.

public class MyToolStripPanel : ToolStripPanel
{
private ToolStripPanelLayout layoutEngine;

public ToolStripPanelLayout()
{
}

public override LayoutEngine LayoutEngine
{
get
{
if (layoutEngine == null)
{
layoutEngine = new ToolStripPanelLayout();
}

return layoutEngine;
}
}
}

// This class demonstrates a simple custom layout engine.
public class ToolStripPanelLayout : LayoutEngine
{
public override bool Layout(
object container,
LayoutEventArgs layoutEventArgs)
{
Control parent = container as Control;

// Use DisplayRectangle so that parent.Padding is honored.
Rectangle parentDisplayRectangle = parent.DisplayRectangle;
Point nextControlLocation = parentDisplayRectangle.Location;

foreach (Control c in parent.Controls)
{
// Only apply layout to visible controls.
if (!c.Visible)
{
continue;
}

// Respect the margin of the control:
// shift over the left and the top.
nextControlLocation.Offset(c.Margin.Left, c.Margin.Top);

// Set the location of the control.
c.Location = nextControlLocation;

// Move X back to the display rectangle origin.
nextControlLocation.X = parentDisplayRectangle.X;

// Increment Y by the height of the control
// and the bottom margin.
nextControlLocation.Y += c.Height + c.Margin.Bottom;
}


// Optional: Return whether or not the container's
// parent should perform layout as a result of this
// layout. Some layout engines return the value of
// the container's AutoSize property.

return false;
}
}

If I do not override the LayoutEngine property of ToolStripPanel , What can I do to prevent the ToolStrip control from changing it's position when other ToolStrip control hided ?

I would be appreciativeof your help.

Typin  Saturday, April 26, 2008 10:04 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridViewComboBoxColumn
• class library's in vb6
• XmlTextWriter
• installing office 2003
• Tool Tip Disappearing
• WinForms app not closing right
• Filling ComboBox From Array
• How to autoresize two controls with a distance between the controls allways staying the same?
• Need help with Side By Side and No Touch
• Why do events still fire on Disposed object?