gpt4 book ai didi

每次更改标签页时都会调用 C# WinForm DrawItem

转载 作者:太空宇宙 更新时间:2023-11-03 12:16:11 28 4
gpt4 key购买 nike

我有一个选项卡控件并在我使用的选项卡标题中放置一个关闭按钮:

private void systemRecordTabControl_DrawItem_1(object sender, DrawItemEventArgs e)
{
e.Graphics.DrawImage(Properties.Resources.icon, e.Bounds.Right - 15, e.Bounds.Top + 3, 11, 11);
e.Graphics.DrawString(systemRecordTabControl.TabPages[e.Index].Text, new Font("Arial", 12, FontStyle.Underline), Brushes.Black, e.Bounds.Left + 12, e.Bounds.Top + 4);
e.DrawFocusRectangle();
}

当程序运行时,每次我在选项卡之间切换时,标题文本会再次绘制在当前选项卡文本的顶部,这导致它非常眼睛酸

例子:

Eewwwww

对比

Mmmmmm

无论如何我可以阻止这种情况发生吗?我不知道如何检查它是否已经绘制

编辑:作为旁注,只有当我将标签页外观设置为“按钮”而 DrawMode 属性为“OwnerDrawFixed”时,才会发生这种情况,同时将焦点更改到另一个控件会导致当前选定的标签页恢复正常(没有文字重叠)

最佳答案

只需重新绘制背景:

    private void systemRecordTabControl_DrawItem_1(object sender, DrawItemEventArgs e)
{
e.DrawBackground(); //<-- Redraw background
e.Graphics.DrawImage(Properties.Resources.icon, e.Bounds.Right - 15, e.Bounds.Top + 3, 11, 11);
e.Graphics.DrawString(systemRecordTabControl.TabPages[e.Index].Text, new Font("Arial", 12, FontStyle.Underline), Brushes.Black, e.Bounds.Left + 12, e.Bounds.Top + 4);
e.DrawFocusRectangle();
}

关于每次更改标签页时都会调用 C# WinForm DrawItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49662601/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com