-2
A
回答
0
更新
根据您的标准改变相当戏剧性,下面是一些代码,它会让你去。它不完美,甚至接近完美!
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
_otherStrips = new List<OtherStrips>();
}
private int _currentHeight = 0;
private List<OtherStrips> _otherStrips;
private void button1_Click(object sender, EventArgs e)
{
foreach (var c in panel1.Controls)
{
if (c is ToolStrip)
{
ToolStrip ts = (ToolStrip)c;
_otherStrips.Add(new OtherStrips() { Top = ts.Top, Width = ts.Width, Name = ts.Name });
MoveToPosition(ts);
}
}
}
private void MoveToPosition(ToolStrip toolStrip)
{
bool isInline;
toolStrip.Left = GetWidth(toolStrip, out isInline);
if (isInline)
toolStrip.Top = GetTop(toolStrip);
}
private int GetWidth(ToolStrip ts, out bool isInline)
{
int result = 0;
isInline = false;
foreach (var item in _otherStrips)
{
if (item.Name == ts.Name)
continue;
if (item.Top == ts.Top)
{
isInline = true;
break;
}
}
if (!isInline)
return result;
foreach (var item in _otherStrips)
{
if (item.Width == ts.Width)
result += item.Width;
}
return result + 22;//hack since the width is out by about 22pixels. Not going to spend any time fixing this
}
private int GetTop(ToolStrip ts)
{
foreach (var item in _otherStrips)
{
if (item.Name == ts.Name)
continue;
if (item.Top == ts.Top)
return item.Top;
}
_currentHeight += ts.Height;
return _currentHeight;
}
}
struct OtherStrips
{
public int Top { get; set; }
public int Width { get; set; }
public string Name { get; set; }
}
0
相关问题
- 1. 将Eclipse工具栏图标左对齐
- 2. 将布局对齐到最左侧工具栏android
- 3. 在Sencha Touch工具栏中左右对齐按钮
- 4. 如何通过代码更改三维主工具栏图标?
- 5. 如何在同一行上对齐2个工具栏,一个对齐左边,一个对齐右边?
- 6. 如何对齐工具栏上的UIBarButtonItem?
- 7. Ios ::工具栏对齐问题
- 8. CKEditor文本对齐工具栏按钮
- 9. WebView和工具栏不会对齐
- 10. 自定义工具栏布局对齐
- 11. 黑莓UI工具栏:字段对齐
- 12. 对齐工具栏中的图标
- 13. HTML左对齐,右对齐不工作
- 14. 右上对齐的MFC工具栏对齐
- 15. 调试工具 - 通过代码
- 16. 如何将工具栏中的元素对齐到左侧,中间和右侧
- 17. 如何对齐我的左侧栏
- 18. 导航栏不会左对齐
- 19. 如何左对齐导航栏文本?
- 20. 如何左对齐的“顶栏”
- 21. 如何让自定义工具栏与操作栏对齐?
- 22. Bootstrap导航栏对齐正确,但需要响应左对齐
- 23. 通过点击按钮在工具栏
- 24. Mac工具栏通过WINE/Crossover
- 25. 通过ToolStripDropDownButton.DropDownItems显示工具栏?
- 26. UITableViewController通过模态工具栏按钮
- 27. 代码对齐行?
- 28. Slidify:代码对齐
- 29. Json对象通过css左对齐重新排列div
- 30. 左右对齐
左对齐工具栏意味着你需要改变的MenuStrip类似的东西现在的位置? – 2013-05-14 10:22:54
我需要从第一个图像的工具栏像第二个图像的工具栏一样对齐。 – serhio 2013-05-14 10:23:44
就这样,我可以确定我已经理解了这个问题,是否当你停靠(DockStyle)时,你不能再应用一个宽度?因此,宽度比你想要的宽得多。 – Dave 2013-05-14 10:52:47