在我的应用中,我希望我的tabcontrol对标题有一个空气动力学效果。这适用于使用此代码的正常winforms tabcontrol:
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):
答案 0 :(得分:0)
没关系 - 找到答案。在OnPaint()Sub中,写
g.Clear(Color.Black)
这会将背景描绘成黑色,因此玻璃效果显示