C#Winforms Panel具有与TabControl相同的样式(阴影)?

编程入门 行业动态 更新时间:2024-10-20 09:22:59
本文介绍了C#Winforms Panel具有与TabControl相同的样式(阴影)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想要一个面板有某种阴影像 TabControl 有,这是可能吗?

I want a panel to have some sort of dropshadow like the TabControl has, is this possible?

推荐答案

BorderStyle = Fixed3D

BorderStyle = Fixed3D

查看此示例中的阴影:

www.onteorasoftware/downloads/panelwithshadow.zip

最后,自定义面板可能类似于(在VB中):

Finally, the custom panel could be like (in 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

更多推荐

C#Winforms Panel具有与TabControl相同的样式(阴影)?

本文发布于:2023-11-06 13:49:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   阴影   Winforms   Panel   TabControl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!