我可以删除 TabControl 上选项卡上的虚线焦点矩形吗?
我有一个选项卡控件,需要删除所选选项卡周围的虚线焦点矩形。
我已将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,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.将焦点设置为选项卡而不是标题(像这样)
您将看到一毫秒的虚线矩形,一旦执行上述事件,它就会消失。
另外,要删除加载时默认选定选项卡的虚线矩形,
这两个更改都对我有用!
希望它对某人有帮助。
Set the focus to tab instead of header (like this)
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
Both this changes worked for me!
hope it helps somebody.