[英]Change the Tab size of tabControl
我為TabControl
重繪了Tab
的圖形,但我無法設置它的Width
。
我想要的是Tab
和圖標的文本包含在其大小中。
現在是這樣的:
我的代碼
private void tabControlForm_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
using (Brush br = new SolidBrush(TabColors[tabControlForm.TabPages[e.Index]]))
{
Rectangle rect = e.Bounds;
rect.Width += 10;
e.Graphics.FillRectangle(br, rect);
SizeF sz = e.Graphics.MeasureString(tabControlForm.TabPages[e.Index].Text, e.Font);
e.Graphics.DrawString(tabControlForm.TabPages[e.Index].Text, e.Font, Brushes.Black, rect.Left + (rect.Width - sz.Width) / 2, rect.Top + (rect.Height - sz.Height) / 2 + 1);
using (var src = new Bitmap(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("Castor.Gestionale.images.close-button.png")))
{
e.Graphics.DrawImage(src, rect.Right - 18, rect.Top + 10);
}
e.Graphics.DrawRectangle(Pens.DarkGray, rect);
e.DrawFocusRectangle();
}
}
catch {}
}
謝謝
嘗試增加“myTabControl.Padding.X”。 這個對我有用!
private void FrmSqlMain_Load(object sender, EventArgs e)
{
myTabControl.SizeMode = TabSizeMode.Normal;
myTabControl.DrawMode = TabDrawMode.OwnerDrawFixed;
}
我還想補充一件事。 起初,我嘗試添加空格,但似乎對我不起作用。 后來,我意識到我必須添加比平時更多的空格才能看到差異。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.