我尝试过使用下面的代码,但它似乎无法正常工作:
Public Class TransparentPanel
Inherits Panel
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
' WS_EX_TRANSPARENT
Return cp
End Get
End Property
Protected Overrides Sub OnPaint(e As PaintEventArgs)
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), Me.ClientRectangle)
End Sub
End Class
' =========================================== ============ ' Telerik提供的服务(www.telerik.com) '转换由NRefactory提供支持。 ' Twitter:@telerik ' Facebook:facebook.com/telerik ' ============================================== =========
这是我的代码:
Imports Telerik.WinControls
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'' RadPanel1.BackColor = Color.Red
RadPanel1.Visible = True
RadPanel1.AutoSize = True
RadPanel1.RootElement.StretchVertically = True
RadPanel1.RootElement.StretchHorizontally = True
RadPanel1.Location = New Point(2, 2)
RadPanel1.Size = New Size(200, 1)
RadPanel1.Text = "I am RadPanel"
Dim setting As New AnimatedPropertySetting()
setting.[Property] = RadElement.BoundsProperty
setting.StartValue = New Rectangle(0, 0, 200, 1)
setting.EndValue = New Rectangle(0, 0, 280, 250)
setting.Interval = 30
setting.NumFrames = 35
setting.ApplyValue(RadPanel1.RootElement)
End Sub
End Class
答案 0 :(得分:1)
在WinForms中使用透明度时,您应该记住,控件只能与其父控件相比才是透明的。因此,如果Form是其父级,您将能够观察与Form相比的RadPanel透明度。但是,如果你有两个RadPanels,两个孩子都是Form,而不是孩子,你就不会在彼此重叠的地方看到透明度。
以下是有关此事的一些文章:
答案 1 :(得分:0)
您是否尝试过使用Alpha属性设置颜色?从我所看到的,其他人已经取得了成功。
RadPanel1.BackColor = Color.FromArgb(100, 88, 44, 55);
How can I set the opacity or transparency of a Panel in WinForms?