我需要将ToolStrip中的标准溢出函数替换为“More ...”按钮,然后弹出带有溢出项目的菜单。有没有人有关于如何做到这一点的任何想法?ToolStrip溢出
1
A
回答
2
我之前写过一些与此类似的东西。我使用的代码粘贴在下面,您可以自由修改它以满足您的需求。
ToolStripCustomiseMenuItem基本上是您单击时填充DropDown上下文菜单的“更多”按钮。希望这可以帮助你,至少这应该是一个很好的起点...
public class ToolStripCustomiseMenuItem : ToolStripDropDownButton {
public ToolStripCustomiseMenuItem()
: base("Add Remove Buttons") {
this.Overflow = ToolStripItemOverflow.Always;
DropDown = CreateCheckImageContextMenuStrip();
}
ContextMenuStrip checkImageContextMenuStrip = new ContextMenuStrip();
internal ContextMenuStrip CreateCheckImageContextMenuStrip() {
ContextMenuStrip checkImageContextMenuStrip = new ContextMenuStrip();
checkImageContextMenuStrip.ShowCheckMargin = true;
checkImageContextMenuStrip.ShowImageMargin = true;
checkImageContextMenuStrip.Closing += new ToolStripDropDownClosingEventHandler(checkImageContextMenuStrip_Closing);
checkImageContextMenuStrip.Opening += new CancelEventHandler(checkImageContextMenuStrip_Opening);
DropDownOpening += new EventHandler(ToolStripAddRemoveMenuItem_DropDownOpening);
return checkImageContextMenuStrip;
}
void checkImageContextMenuStrip_Opening(object sender, CancelEventArgs e) {
}
void ToolStripAddRemoveMenuItem_DropDownOpening(object sender, EventArgs e) {
DropDownItems.Clear();
if (this.Owner == null) return;
foreach (ToolStripItem ti in Owner.Items) {
if (ti is ToolStripSeparator) continue;
if (ti == this) continue;
MyToolStripCheckedMenuItem itm = new MyToolStripCheckedMenuItem(ti);
itm.Checked = ti.Visible;
DropDownItems.Add(itm);
}
}
void checkImageContextMenuStrip_Closing(object sender, ToolStripDropDownClosingEventArgs e) {
if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) {
e.Cancel = true;
}
}
}
internal class MyToolStripCheckedMenuItem : ToolStripMenuItem {
ToolStripItem tsi;
public MyToolStripCheckedMenuItem(ToolStripItem tsi)
: base(tsi.Text) {
this.tsi = tsi;
this.Image = tsi.Image;
this.CheckOnClick = true;
this.CheckState = CheckState.Checked;
CheckedChanged += new EventHandler(MyToolStripCheckedMenuItem_CheckedChanged);
}
void MyToolStripCheckedMenuItem_CheckedChanged(object sender, EventArgs e) {
tsi.Visible = this.Checked;
}
}
0
您可以捕获按钮上的漆事件致电
toolStrip1.OverflowButton.Paint += new PaintEventHandler(OverflowButton_Paint);
这在理论上应该让你做它说“更多...”,但我无法设置溢出的宽度按钮只是(窄)默认宽度。
此外,另一个想法是,您可以在OverflowButton上捕获VisibleChanged
,然后在工具栏中手动插入拆分按钮。棘手的部分是弄清楚该放哪个按钮。
相关问题
- 1. js溢出函数溢出
- 2. ToolStrip LineStyles .Net
- 3. 在winform的ToolStrip
- 4. 缓冲区溢出(VS)缓冲区溢出(VS)堆栈溢出
- 5. 溢出
- 6. 溢出
- 7. ToolStrip按钮闪烁
- 8. 缓冲区溢出不溢出
- 9. Hypertable启动时溢出内存溢出
- 10. CSS溢出:强制一个div溢出
- 11. 在x64上没有溢出溢出
- 12. basic_streambuf函数如何溢出和溢出
- 13. 溢出-y覆盖溢出-y
- 14. CannyEdgeDetector给位图溢出溢出
- 15. C++下溢和溢出
- 16. 检查C++下溢/溢出?
- 17. ItemsControl“溢出弹出”
- 18. strcat溢出?
- 19. PHP表溢出
- 20. 堆栈溢出
- 21. UITextField溢出
- 22. 隐藏溢出
- 23. 溢出在RStudio
- 24. logcat溢出
- 25. CSS DIV溢出
- 26. Bootstrap溢出
- 27. 检查溢出
- 28. css td溢出
- 29. openCL Long溢出
- 30. 膨胀溢出