Click here to Skip to main content
15,892,746 members
Articles / Desktop Programming / Windows Forms

i00 Spell Check and Control Extensions - No Third Party Components Required!

Rate me:
Please Sign up or sign in to vote.
4.95/5 (117 votes)
11 Jan 2014Ms-PL16 min read 1.3M   22   266  
Simple to use, open source Spell Checker for .NET
'i00 .Net HTML Menu Item
'©i00 Productions All rights reserved
'Created by Kris Bennett
'----------------------------------------------------------------------------------------------------
'All property in this file is and remains the property of i00 Productions, regardless of its usage,
'unless stated otherwise in writing from i00 Productions.
'
'i00 is not and shall not be held accountable for any damages directly or indirectly caused by the
'use or miss-use of this product.  This product is only a component and thus is intended to be used 
'as part of other software, it is not a complete software package, thus i00 Productions is not 
'responsible for any legal ramifications that software using this product breaches.

<System.ComponentModel.DesignerCategory("")> _
Public Class HTMLMenuItem
    Inherits ToolStripDropDownItem

    Dim mc_HTMLText As String
    Public Property HTMLText() As String
        Get
            Return mc_HTMLText
        End Get
        Set(ByVal value As String)
            If value = "" Then value = " "
            Dim ToBeWidth As Integer
            Dim ToBeHeight As Integer

            mc_HTMLText = value
            Me.AutoSize = False
            Dim theSize = GetHTMLInfo.Size
            If theSize.Width > 400 Then
                ToBeWidth = 400
                theSize = GetHTMLInfo(400).Size
            Else
                ToBeWidth = CInt(theSize.Width) + 1
            End If
            If theSize.Height > SmallHeight + SmallHeightTolerance Then
                ToBeHeight = SmallHeight
                BigHeight = CInt(theSize.Height) + 1
            Else
                ToBeHeight = CInt(theSize.Height) + 1
                BigHeight = ToBeHeight
            End If

            If Me.Width <> ToBeWidth Then
                Me.Width = ToBeWidth
            End If
            If Me.Height <> ToBeHeight Then
                Me.Height = ToBeHeight
            End If

        End Set
    End Property
    Public Overrides Property Text() As String
        Get
            Return MyBase.Text
        End Get
        Set(ByVal value As String)
            MyBase.Text = ""
        End Set
    End Property

    Public Overrides ReadOnly Property HasDropDownItems() As Boolean
        Get
            Return True
        End Get
    End Property

    Public Sub New(ByVal HTMLText As String)
        Me.HTMLText = HTMLText
    End Sub

    Const SmallHeightTolerance As Integer = 16
    Public SmallHeight As Integer = 100
    Dim BigHeight As Integer

    <System.ComponentModel.Browsable(False)> _
    Overrides ReadOnly Property CanSelect() As Boolean
        Get
            Return BigHeight > SmallHeight AndAlso Me.Height <> BigHeight
        End Get
    End Property

    Private Sub tsiDefinition_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        Expand()
    End Sub

    Public Sub Expand()
        If CanSelect Then
            'means we have too much stuff
            If Me.Height = SmallHeight Then
                Me.Height = BigHeight
            Else
                'make it grow back?
                'qwertyuiop - put on timer to prevent close if after shrink cursor location is off the menu?
                'Me.Height = SmallHeight
            End If
        End If
    End Sub

    Private Sub tsiDefinition_DropDownOpening(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DropDownOpening
        'pressed enter :)
        Expand()
    End Sub

    Dim MouseOver As Boolean
    Private Sub tsiDefinition_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
        If MouseOver = False Then
            MouseOver = True
            Me.Invalidate()
        End If
    End Sub

    Private Sub tsiDefinition_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
        If MouseOver = True Then
            MouseOver = False
            Me.Invalidate()
        End If
    End Sub

    Public Function GetHTMLInfo(Optional ByVal MaxWidth As Single = -1) As HTMLParser.PaintHTMLReturn
        Dim status As New HTMLParser.Status
        status.Font = New HTMLParser.STRFont(System.Drawing.SystemFonts.MenuFont)
        status.Brush = New HTMLParser.STRBrush(Color.FromKnownColor(KnownColor.MenuText))

        Return HTMLParser.PaintHTML(HTMLText, , MaxWidth, status)
    End Function

    Private Sub tsiDefinition_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim status As New HTMLParser.Status
        status.Font = New HTMLParser.STRFont(System.Drawing.SystemFonts.MenuFont)
        status.Brush = New HTMLParser.STRBrush(Color.FromKnownColor(KnownColor.MenuText))

        If CanSelect Then
            'draw the expander ...checked in the CanSelect :)
            Using tsi As New ToolStripMenuItem 'ToolStripButton
                tsi.AutoSize = False
                tsi.Width = Me.Width
                tsi.Height = CInt(tsi.Height / 2)
                tsi.Select()
                Dim ExpandBarRect As New Rectangle(0, Me.Height - tsi.Height, tsi.Width, tsi.Height)
                Using r As New Region
                    r.Exclude(ExpandBarRect)
                    e.Graphics.Clip = r
                    HTMLParser.PaintHTML(HTMLText, e.Graphics, MyBase.Width, status)
                    e.Graphics.ResetClip()
                End Using

                Using b As New Bitmap(tsi.Width, tsi.Height)
                    Using g = Graphics.FromImage(b)
                        Me.Parent.Renderer.DrawMenuItemBackground(New ToolStripItemRenderEventArgs(g, tsi))

                        Using tsmi As New ToolStripMenuItem
                            tsmi.Width = tsi.Width
                            tsmi.Height = tsi.Height
                            tsmi.AutoSize = False
                            Me.Parent.Renderer.DrawArrow(New ToolStripArrowRenderEventArgs(g, tsmi, New Rectangle(0, 0, tsi.Width, tsi.Height), Color.FromKnownColor(KnownColor.MenuText), ArrowDirection.Down))
                        End Using
                        If MouseOver OrElse Me.Selected Then
                            e.Graphics.DrawImage(b, ExpandBarRect)
                        Else
                            'DrawingFunctions.Grayscale(b)
                            DrawingFunctions.AlphaImage(e.Graphics, b, ExpandBarRect)
                        End If
                    End Using
                End Using
            End Using
        Else
            'just draw
            HTMLParser.PaintHTML(HTMLText, e.Graphics, MyBase.Width, status)
        End If

    End Sub
End Class

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 Microsoft Public License (Ms-PL)


Written By
i00
Software Developer (Senior) i00 Productions
Australia Australia
I hope you enjoy my code. It's yours to use for free, but if you do wish to say thank you then a donation is always appreciated.
You can donate here.

Comments and Discussions