Je veux un panneau pour avoir une sorte de dropshadow comme le TabControl
a, est-ce possible?C# Winforms Panel avec le même style (ombre) que TabControl?
Répondre
BorderStyle = Fixed3D
un coup d'oeil à l'ombre dans cet exemple:
http://www.onteorasoftware.com/downloads/panelwithshadow.zip
Enfin, le panneau personnalisé pourrait être comme (en VB):
Imports System.Drawing.Drawing2D
Public Class ShadowPanel
Inherits Panel
Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer
Public Sub New()
Me.BorderStyle = BorderStyle.Fixed3D
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_NCPAINT As Integer = &H85
If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width - 1, Me.Height - 1)
Dim pBottom As Pen = New Pen(Color.Gray, 3)
Dim pTop As Pen = New Pen(Color.White, 3)
g.DrawRectangle(pBottom, rDraw)
Dim pts(2) As Point
pts(0) = New Point(0, Me.Height - 1)
pts(1) = New Point(0, 0)
pts(2) = New Point(Me.Width - 1, 0)
g.DrawLines(pTop, pts)
ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)
End If
End Sub
Private Sub ParentPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = Me.Parent.CreateGraphics
'this matrix zooms the text out to 1/4 size and offsets it by a little right and down
Dim mx As New Matrix(1.0F, 0, 0, 1.0F, 4, 4)
Dim rdraw As New Rectangle(Me.Left, Me.Top, Me.Width, Me.Height)
g.Transform = mx
g.FillRectangle(New SolidBrush(Color.FromArgb(128, Color.Black)), rdraw)
g.Dispose()
End Sub
End Class
oui, dans l'événement de peinture de votre panneau, utilisez quelque chose comme ceci:
void Paint(object sender, PaintEventArgs e) {
TabRenderer.DrawTabPage(e.Graphics, e.Bounds);
}
exception indiquant que les styles visuels ne sont pas activés ... (this.Bounds) – serhio
Fonctionne avec panel.Bounds. e ne contient pas de limites – MysticEarth
@MysticEarth: Pondidum signifiait créer un myPanel: Panel personnalisé et remplacer OnPaint, n'est-ce pas? – serhio
- 1. Définition des propriétés d'alignement TabControl. C# Winforms
- 2. tabcontrol ownerdraw modifie le style de bordure du tabcontrol
- 3. Winform TabControl style
- 4. C# Tab commutation dans TabControl
- 5. Icônes dans TabControl C# - Comment?
- 6. TabItems de TabControl partageant le même contenu ... Ne pas vouloir
- 7. DataTrigger ne fonctionne que sur le premier TabItem dans TabControl
- 8. C#: transparent dans tabControl
- 9. .Net WinForms TabControl Steals Focus sur l'activation des formulaires
- 10. Winforms TabControl provoquant de faux événements Paint pour UserControl
- 11. C# tabcontrol - tabulation
- 12. Ombre transparente avec jQuery
- 13. comment changer le nom du tabcontrol
- 14. UIView arrondi avec ombre?
- 15. div ombre avec jquery
- 16. problème scrollviewer avec tabcontrol
- 17. C# TabControl TabPage Change
- 18. WPF TabControl Templates + ItemContainerStyle
- 19. MainMenu avec images (WinForms, C#)
- 20. Définir la visibilité sur un seul onglet dans tabcontrol (winforms)
- 21. Winforms Création d'un panneau de style Dropdown
- 22. Winforms avec MEF
- 23. Div avec le style "display: none" apparaît quand même
- 24. jQuery Panel - fonction slideOut et fadeIn en même temps problème
- 25. Problème avec l'alignement TabControl dans VB.NET
- 26. WPF TabControl avec le bouton 'nouvel onglet'?
- 27. override C# Méthode TabControl add
- 28. Winforms C#: graphics.DrawImage problème
- 29. Définition du style de contrôle des onglets sur TabControl managé
- 30. Transparence partielle avec C# .NET 3.5 WinForms?
+1, simplicité> peinture! – Pondidum
ceci donne au panneau une apparence d'encart, et je veux qu'il laisse tomber l'ombre ... – MysticEarth
@ Earth: voir mon édition. – serhio