TabControl 中的轨迹栏背景

发布于 2024-07-14 17:35:56 字数 200 浏览 8 评论 0原文

我在 TabControl 内的 TabPage 上有一个 TrackBar 控件。 TrackBar 的背景绘制为灰色,而 TabPage 的背景绘制为白色。 无法将 TrackBar 的 BackColor 属性设置为透明,并且我无法覆盖绘图,因为 TrackBar 没有 DrawMode 属性。 我必须有哪些选项才能使 TrackBar 适合? 为什么它不支持视觉样式?

I have a TrackBar control on a TabPage inside a TabControl. The background of the TrackBar is being drawn in grey while the TabPage is being drawn as white. There is no way to set the BackColor property of the TrackBar to transparent, and I can't override the drawing because there is no DrawMode property for the TrackBar. What options do I have to make the TrackBar fit in? Why doesn't it support visual styles?

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

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

发布评论

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

评论(5

非要怀念 2024-07-21 17:35:56

简单

class MyTransparentTrackBar : TrackBar
{
    protected override void OnCreateControl()
    {
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        if (Parent != null)
            BackColor = Parent.BackColor;

        base.OnCreateControl();
    }
}

我也面临着这个问题(需要在选项卡控件上有一个透明背景的轨迹栏,它将与启用和禁用的视觉样式一起使用)。 这对我有用。

Simple

class MyTransparentTrackBar : TrackBar
{
    protected override void OnCreateControl()
    {
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        if (Parent != null)
            BackColor = Parent.BackColor;

        base.OnCreateControl();
    }
}

I also faced this (needed a transparent-background trackbar on a tab-control, that will work with both visualstyles enabled and disabled). And this worked for me.

策马西风 2024-07-21 17:35:56

不会在这里干涉,但上述建议都不适合我。
诀窍是以下几行:

private const int WM_DWMCOMPOSITIONCHANGED = 0x031A;
private const int WM_THEMECHANGED = 0x031E;

protected override void OnVisibleChanged(EventArgs e)
{
    Color color = this.BackColor;
    trackBarQuality.BackColor = Color.FromArgb(color.R, color.G, color.B);
}

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_DWMCOMPOSITIONCHANGED || m.Msg == WM_THEMECHANGED)
        OnVisibleChanged(new EventArgs());

    base.WndProc(ref m);
}

所以我基本上消除了背景颜色中的 alpha 通道。 不过,仍然需要在 Vista 和 Win 7 上进行测试。

Wouldn't interfere here, but neither of the above suggestions worked for me.
What did the trick were the following lines:

private const int WM_DWMCOMPOSITIONCHANGED = 0x031A;
private const int WM_THEMECHANGED = 0x031E;

protected override void OnVisibleChanged(EventArgs e)
{
    Color color = this.BackColor;
    trackBarQuality.BackColor = Color.FromArgb(color.R, color.G, color.B);
}

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_DWMCOMPOSITIONCHANGED || m.Msg == WM_THEMECHANGED)
        OnVisibleChanged(new EventArgs());

    base.WndProc(ref m);
}

So I basically eliminate the alpha channel from the background color. Still have to test this with Vista and Win 7, though.

烟火散人牵绊 2024-07-21 17:35:56

您可能想查看 CodePlex 上的 TransparentTrackBar 项目。

You might want to look at the TransparentTrackBar project on CodePlex.

旧人九事 2024-07-21 17:35:56
internal class TransparentTrackBar : System.Windows.Forms.TrackBar
{
    protected override void OnCreateControl()
    {
        VisualStyleRenderer oRenderer = new VisualStyleRenderer(
          VisualStyleElement.Tab.Pane.Normal);

        BackColor = oRenderer.GetColor(ColorProperty.FillColorHint);
            base.OnCreateControl();
    }
}
internal class TransparentTrackBar : System.Windows.Forms.TrackBar
{
    protected override void OnCreateControl()
    {
        VisualStyleRenderer oRenderer = new VisualStyleRenderer(
          VisualStyleElement.Tab.Pane.Normal);

        BackColor = oRenderer.GetColor(ColorProperty.FillColorHint);
            base.OnCreateControl();
    }
}
佼人 2024-07-21 17:35:56

显而易见的解决方案似乎是将 TrackBar 的 BackColor 设置为 System-ControlLightLight。

(但是对于四年前的问题的明显解决方案的问题是,它可能意味着我误解了某些东西。)

The obvious solution seems to be to set the TrackBar's BackColor to System-ControlLightLight.

(But the problem with an obvious solution to four-year-old question is that it probably implies that I've misunderstood something.)

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