English 中文(简体)
公平和透明的背景
原标题:TabControl transparent background
  • 时间:2009-09-06 06:13:16
  •  标签:

I d like to know if there s some way to render the background of a TabControl transparent (the TabControl, not the TabPages), instead of taking the parent form background color. I ve some forms with custom painting where I draw a gradient as the background but this gradient doesn t paint behind the tabcontrols. I tried setting TabControl.Backcolor = Color.Transparent but it tells me it s not supported. I m using VS2005 and framework 2.0. (set style does not help) Does anyone have good workaround to this issue?

问题回答

习俗:

[DllImport("uxtheme", ExactSpelling = true)]
public extern static Int32 DrawThemeParentBackground(IntPtr hWnd, IntPtr hdc, ref Rectangle pRect);

protected override void OnPaintBackground(PaintEventArgs e)
{
    if (this.BackColor == Color.Transparent)
    {
        IntPtr hdc = e.Graphics.GetHdc();
        Rectangle rec = new Rectangle(e.ClipRectangle.Left,
            e.ClipRectangle.Top, e.ClipRectangle.Width, e.ClipRectangle.Height);
        DrawThemeParentBackground(this.Handle, hdc, ref rec);
        e.Graphics.ReleaseHdc(hdc);
    }
    else
    {
        base.OnPaintBackground(e);
    }
}

,该表层在mdn 上,但该表层控制不支持将背书人改为透明,但你本可以推翻提款方法。

我将回答<代码>Golan(因为他不活动?)

http://msdn.microsoft.com/en-us/library/windows/desktop/bb77330628v=vs.85%29.aspx“rel=” 大部分工作由ParentBackground进行。 建立习俗:

[System.ComponentModel.DesignerCategory("Code")]
public class MyTabControl : TabControl
{

    [DllImport("uxtheme", ExactSpelling = true)]
    public extern static Int32 DrawThemeParentBackground(IntPtr hWnd, IntPtr hdc, ref Rectangle pRect);

    // use with care, as it may cause strange effects
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
            return cp;
        }
    } 

    public MyTabControl() { }

    protected override void OnPaintBackground(PaintEventArgs e)
    {
        IntPtr hdc = e.Graphics.GetHdc();
        Rectangle rect = ClientRectangle;
        DrawThemeParentBackground(this.Handle, hdc, ref rect);
        e.Graphics.ReleaseHdc(hdc);
    }
}

。 (在设计或操作期间,如果你没有——<代码>TabPages,则有白色背景。) 象一个奇迹、透明、无浮标的塔克特工程,我梦想这样做。





相关问题
热门标签