Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / multimedia / GDI

MBGlassPanel Using VB.NET 2008

3.75/5 (7 votes)
9 Jul 2012CPOL 27.7K   2.2K  
MBGlassPanel with Microsoft Office Ribbon Visual Style

Image 1

Introduction

Why another Panel? This is a User Control with Microsoft Office Ribbon Visual Style. It is simple to use, just drop it on the form, and use it like the normal Panel.

Background

MBPanel is a Panel which inherits all the properties of simple Panel control. I added Microsoft Office Ribbon like Visuals in MBPanel. The language used is VB.NET. To Use this Control in your Application or Project You Just add the reference of MBPanel.Dll and used it by Dragging and Dropping.

Using the code

The concept for this MBPanel came from the Microsoft Office Ribbon Panel. I organized methods of MBPanel into layers like this:

Following methods which are responsible for rendering simple Panel like Microsoft office Ribbon Panel. This method Render Background of MBPanel:

VB.NET
''' <summary>
''' Paint Backround Surface Of MBPanel
''' </summary />
Private Sub PaintBackgoundSurface(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
     With e.Graphics
           .SmoothingMode = SmoothingMode.HighQuality
           .TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
           .CompositingQuality = CompositingQuality.HighQuality
     End With
     Dim brGlass As New SolidBrush(Color.FromArgb(CheckOpacity(Opacity), _
                    GlassColor.R, GlassColor.G, GlassColor.B))
     e.Graphics.FillPath(brGlass, RoundSurface)
     PaintHorizontalSurface(sender, e)
     PaintGlowSurface(sender, e)
     PaintReflectiveBands(sender, e)
     PaintLightSource(sender, e)
End Sub

This method Paint Reflective Bands for MBPanel:

VB.NET
 ''' <summary>
''' Paint ReflectiveBands for MBPanel
''' </summary />
Private Sub PaintReflectiveBands(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    Dim brGlassReflect As New SolidBrush(Color.FromArgb(CheckOpacity(Opacity * 0.5), GlassColor.R, GlassColor.G, GlassColor.B))
    Dim grpBand1 As GraphicsPath = CreateReflectiveBand(0.1!, 0.5!, 0.15!)
    Dim grpBand2 As GraphicsPath = CreateReflectiveBand(0.4!, 0.8!, 0.1!)
    e.Graphics.FillPath(brGlassReflect, grpBand1)
    e.Graphics.FillPath(brGlassReflect, grpBand2)
End Sub 

This method Paint Reflective Bands for MBPanel:

VB.NET
''' <summary>
''' Paint ReflectiveBands for MBPanel
''' </summary />
Private Sub PaintReflectiveBands(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    Dim brGlassReflect As New SolidBrush(Color.FromArgb(CheckOpacity(Opacity * 0.5), GlassColor.R, GlassColor.G, GlassColor.B))
    Dim grpBand1 As GraphicsPath = CreateReflectiveBand(0.1!, 0.5!, 0.15!)
    Dim grpBand2 As GraphicsPath = CreateReflectiveBand(0.4!, 0.8!, 0.1!)
    e.Graphics.FillPath(brGlassReflect, grpBand1)
    e.Graphics.FillPath(brGlassReflect, grpBand2)
End Sub

This method Paint Border for MBPanel:

VB.NET
''' <summary>
''' Paint Border of MBPanel
''' </summary />
Private Sub PaintBorder(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    If _BorderStyle = MBBorderStyle.Rounded Then
        e.Graphics.DrawPath(New Pen(Color.FromArgb(200, 255, 255, 255), 0.5!), RoundSurface)
        e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 0, 0, 0), 0.5!), RoundSurfaceInner)
    End If
End Sub

How to use

Image 2

It is very easy to use the MBPanel in your application. Just add the reference of the provided DLL to your application and just drag and drop.

History

  • MBPanel Version 1.0.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)