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?
公平和透明的背景
原标题:TabControl transparent background
问题回答
习俗:
[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);
}
}
我将回答<代码>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);
}
}
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabpage.use pornographyebackcolor(v=vs.110).aspx”rel=“nofollow” 可在MSDN上解释。
- Check if
Application.RenderWithVisualStyles
returns true - Have the TabPage s
UseVisualStyleBackColor
property set to true - Have the TabControl
Appearance
property set toNormal
那么,贵邮局应有透明的背景。
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding