-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. 如何通過代碼更改三維主工具欄圖標?
- 4. 如何在同一行上對齊2個工具欄,一個對齊左邊,一個對齊右邊?
- 5. 自定義工具欄佈局對齊
- 6. 對齊工具欄中的圖標
- 7. 黑莓UI工具欄:字段對齊
- 8. Ios ::工具欄對齊問題
- 9. 右上對齊的MFC工具欄對齊
- 10. 如何對齊我的左側欄
- 11. 導航欄不會左對齊
- 12. 如何左對齊的「頂欄」
- 13. 如何左對齊導航欄文本?
- 14. Bootstrap導航欄對齊正確,但需要響應左對齊
- 15. 將右欄放在左欄旁邊,而不是右欄對齊
- 16. 通過ToolStripDropDownButton.DropDownItems顯示工具欄?
- 17. Mac工具欄通過WINE/Crossover
- 18. 左右對齊
- 19. TD工作中心和左對齊但不對對齊
- 20. 工具欄左側插入/填充
- 21. 顯示柔性盒居中但左對齊項左左對齊
- 22. 如何通過代碼對齊joomla插件
- 23. 工具提示對齊
- 24. 將圖標與工具欄圖標對齊 - Android Material Design
- 25. 工具欄標題的項目對齊問題?
- 26. Bootstrap對齊工具欄按鈕來填充entier行寬度
- 27. 如何設置QMenu以對齊到工具欄的右側?
- 28. 如何與工具欄的標題對齊?
- 29. 工具欄在發佈版本中未對齊
- 30. 工具欄中的標題圖像對齊方式android
左對齊工具欄意味着你需要改變的MenuStrip類似的東西現在的位置? – 2013-05-14 10:22:54
我需要從第一個圖像的工具欄像第二個圖像的工具欄一樣對齊。 – serhio 2013-05-14 10:23:44
就這樣,我可以確定我已經理解了這個問題,是否當你停靠(DockStyle)時,你不能再應用一個寬度?因此,寬度比你想要的寬得多。 – Dave 2013-05-14 10:52:47