我可以删除 TabControl 上选项卡上的虚线焦点矩形吗?

发布于 2024-10-21 00:40:46 字数 579 浏览 1 评论 0原文

我有一个选项卡控件,需要删除所选选项卡周围的虚线焦点矩形。

我已将 TabControl 的 TabStop 属性设置为 false。但是,如果我单击选项卡并按 Tab 键,则选项卡名称周围会出现虚线矩形。

我尝试创建自己的 TabControl 并尝试了这个

class MyTabControl : TabControl
{
        public MyTabControl()
        {
            TabStop = false;
            DrawMode = TabDrawMode.OwnerDrawFixed;
            DrawItem += new DrawItemEventHandler(DoMoreTabControl_DrawItem);
            Invalidate();
        }
}

但是,虚线矩形仍然出现。

我还尝试重写 MyTabControl.OnPaint() 方法,但没有帮助。

有什么办法可以实现这一点吗?

I have a tab control and need to remove the dotted focus rectangle around the selected tab.

I have set the TabStop property of the TabControl to false. However if I click on a tab and press the Tab key, the dotted rectangle appears around the tabname.

I have tried creating my own TabControl and tried this

class MyTabControl : TabControl
{
        public MyTabControl()
        {
            TabStop = false;
            DrawMode = TabDrawMode.OwnerDrawFixed;
            DrawItem += new DrawItemEventHandler(DoMoreTabControl_DrawItem);
            Invalidate();
        }
}

However, the dotted rectangle still appears.

I also tried overriding the MyTabControl.OnPaint() method but it doesn't help.

Is there any way to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相权↑美人 2024-10-28 00:40:47

是的,DrawItem 事件。你没有发布它,不可能猜出它有什么问题。只需确保您没有调用 e.DrawFocusRectangle(),它可能在您复制 MSDN 示例代码时出现。只需删除该语句就足够了。考虑使用不同的背景颜色或文本字体样式作为替代方案,这样焦点提示就不会完全丢失。

Yes, DrawItem event. You didn't post it, impossible to guess what's wrong with it. Just make sure that you don't call e.DrawFocusRectangle(), likely to present when you copied the MSDN sample code. Simply deleting the statement is sufficient. Consider using a different background color or text font style as an alternative so the focus hint isn't entirely lost.

玩世 2024-10-28 00:40:46

将焦点设置为选项卡而不是标题(像这样)

private void tabControl1_Click(object sender, EventArgs e)
{
    (sender as TabControl).SelectedTab.Focus();
}

您将看到一毫秒的虚线矩形,一旦执行上述事件,它就会消失。

另外,要删除加载时默认选定选项卡的虚线矩形,

private void tabControl1_Enter(object sender, EventArgs e)
{
    (sender as TabControl).SelectedTab.Focus();
}

这两个更改都对我有用!
希望它对某人有帮助。

Set the focus to tab instead of header (like this)

private void tabControl1_Click(object sender, EventArgs e)
{
    (sender as TabControl).SelectedTab.Focus();
}

You will see dotted rectangle for a millisecond, as soon as the above event gets executed it will disappear.

Also, to remove dotted rectangle for default selected tab on load

private void tabControl1_Enter(object sender, EventArgs e)
{
    (sender as TabControl).SelectedTab.Focus();
}

Both this changes worked for me!
hope it helps somebody.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文