如何从选项卡控件中删除虚线的焦点矩形? [英] How to remove dotted focus rectangle from tab control?
本文介绍了如何从选项卡控件中删除虚线的焦点矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从自定义Tab Control
中删除点聚焦矩形.我已经尝试了所有方法,但无法删除该矩形.
I'm trying to remove dotted focus rectangle from my custom Tab Control
. I've tried everything and I could not remove that rectangle.
如您在图片中所见,聚焦矩形在我的应用程序设计中令人不安.
As you can see in the picture, the focus rectangle is disturbing in my application design.
请帮助!
推荐答案
要删除焦点提示,您必须将UserPaint
设置为true,然后自己绘制整个选项卡控件,包括边框,文本,背景,突出显示,热跟踪等.
To remove the focus cue, you have to set UserPaint
to true, and then paint the entire tab control yourself, including the borders, text, backgrounds, highlighting, hot-tracking, etc.
以下代码仅绘制标签文本和背景:
The following code only paints the tab text and the background:
public class TC2 : TabControl {
public TC2() {
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
var g = e.Graphics;
TabPage currentTab = this.SelectedTab;
for (int i = 0; i < TabPages.Count; i++) {
TabPage tp = TabPages[i];
Rectangle r = GetTabRect(i);
Brush b = (tp == currentTab ? Brushes.LightSteelBlue : Brushes.LightGray);
g.FillRectangle(b, r);
TextRenderer.DrawText(g, tp.Text, tp.Font, r, tp.ForeColor);
}
}
protected override void OnPaintBackground(PaintEventArgs e) {
base.OnPaintBackground(e);
}
}
这篇关于如何从选项卡控件中删除虚线的焦点矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文