【发布时间】:2015-04-17 15:19:28
【问题描述】:
我正在尝试在 tabcontrol 的标签页面板上添加关闭按钮或“X”,并且通过阅读此 stackoverflow question 已成功完成此操作。
问题是标签页标题和 X 符号合并在一起。我发现标签页标题面板没有根据标题文本调整大小。
代码如下:
//This code will render a "x" mark at the end of the Tab caption.
e.Graphics.DrawString("X", e.Font, Brushes.Black, e.Bounds.Right + 15, e.Bounds.Top + 4);
e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left+5, e.Bounds.Top + 4);
e.DrawFocusRectangle();
结果是这里我已经更改了e.bounds.right 的值,但它仍然无法正常工作。
【问题讨论】:
-
这取决于 SizeMode。您可能希望在文本中添加几个空格以强制为 X 留出空间。或者您可以在将 X 添加到实际文本之前使用 measurestring 填充足够的空格,而无需单独绘制它。你将无法通过这种方式控制外观..