Click here to Skip to main content
15,892,480 members
Articles / General Programming / File

VB 9.0, C# 3.0 API Viewer

Rate me:
Please Sign up or sign in to vote.
4.35/5 (10 votes)
24 May 2012CPOL5 min read 80.2K   4.2K   42  
This is a remake of Pramod Kumar Sing's 2002 API Viewer.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Namespace CustomControls
    ''' <summary>
    ''' The labeled divider provides a Aero styled divider with an option caption, similiar to what is seen in the
    ''' Control Panel dialogs of Windows 7 and Vista.
    ''' </summary>
    Public Class DividerControl
        Inherits Control

        Public Sub New()
            SetStyle(ControlStyles.AllPaintingInWmPaint Or _
                ControlStyles.DoubleBuffer Or _
                ControlStyles.ResizeRedraw Or _
                ControlStyles.SupportsTransparentBackColor Or _
                ControlStyles.UserPaint, True)

            Me.Font = New Font("Tahoma", 9, FontStyle.Regular, GraphicsUnit.Point, 0)
            Me._text = Me.Name
            Me.ForeColor = Color.Gray
            Me.Width = 200
        End Sub

        Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            MyBase.OnPaint(e)

            Dim sbDividerColor As New SolidBrush(Me._dividerColor)
            Dim sbForeColor As New SolidBrush(Me.ForeColor)

            ' Draw the caption string, then get the size of it as it appears on the screen so
            ' we know where to put the caption.
            e.Graphics.DrawString(Me.Text, Me.Font, sbForeColor, 0, 0)
            Dim sf As SizeF = e.Graphics.MeasureString(Me.Text, Me.Font)

            ' This didn't quiet get in the center so I had to add 1 pixel to the sf.Height / 2

            Dim rect As New Rectangle(CInt(sf.Width), CInt((sf.Height) / 2) + 1, Me.Width - CInt(sf.Width), 1)
            e.Graphics.FillRectangle(sbDividerColor, rect)

            sbForeColor.Dispose()
            sbDividerColor.Dispose()
        End Sub

        Private _dividerColor As Color = Color.FromArgb(176, 191, 222)
        ''' <summary>
        ''' The color of the divider line.
        ''' </summary>
        <Description("The color of the divider line."), Category("Appearance")> _
        Public Property DividerColor() As Color
            Get
                Return Me._dividerColor
            End Get
            Set(ByVal value As Color)
                Me._dividerColor = value
            End Set
        End Property

        Private _text As String = ""
        ''' <summary>
        ''' The text that should be used for the caption.  If the caption is set to blank and the divider position is set to center then
        ''' a simple divider line will be drawn.
        ''' </summary>
        ''' <remarks>
        ''' After a change is made to the text property we want to invalidate the control so it triggers a new paint message being sent.
        ''' </remarks>
        <Description("The text that will display as the caption."), Category("Appearance"), DefaultValue("DividerLabel")> _
        Public Overloads Overrides Property Text() As String
            Get
                Return Me._text
            End Get
            Set(ByVal value As String)
                Me._text = value
                Me.Invalidate()
            End Set
        End Property

    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Retired
United States United States
I am currently retired.
I have no degree but I have some programming experience
when I was in college(Cobol, Pascal).

My accomplishments thus far are;
Best VB.Net article for January(2009)
Best VB.Net article for July(2009)

Comments and Discussions