0
在我的應用程序中,我希望我的tabcontrol在標題上具有aero效果。這適用於正常的WinForms TabControl的使用此代碼:用戶繪製TabControl上的Aero效果
Imports System.Runtime.InteropServices
<DllImport("dwmapi.dll")> _
Private Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef pMarInset As MARGINS) As Integer
End Function
<StructLayout(LayoutKind.Sequential)> _
Private Structure MARGINS
Public cxLeftWidth As Integer
Public cxRightWidth As Integer
Public cyTopHeight As Integer
Public cyBottomHeight As Integer
End Structure
問題是,我有一個自定義的TabControl類(與實際要大得多,並且具有更爲複雜的OnPaint()重寫比下文)
Public Class CustomTab
Inherits TabControl
Public Sub New()
SetStyle(ControlStyles.UserPaint or ControlStyles.ResizeRedraw,True)
End Sub
Protected Overrides Sub OnPaint(e as PaintEventArgs)
Dim g as Graphics = e.Graphics
Dim r as Rectangle
For i=0 to TabCount - 1
If i = SelectedIndex
r = GetTabRect(i)
g.FillRectangle(New SolidBrush(My.Settings.TabColor),r)
Else
r = GetTabRect(i)
g.FillRectangle(New SolidBrush(SystemColors.Control),r)
End If
Next
End Sub
End Class
當我嘗試使用這個玻璃效果時,它不會像正常一樣顯示在標題中。 有誰知道爲什麼Userdrawn tabcontrol沒有透明頭文件?
工作(普通的TabControl):
不工作(我的TabControl):