Results 1 to 14 of 14

Thread: Show NUD with Inches mark

Threaded View

  1. #14

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Show NUD with Inches mark

    Updated the code to include Nick's suggestion, also created a UnitCharChanged event too.
    vb Code:
    1. Imports System.ComponentModel
    2.  
    3. <ToolboxBitmap(GetType(NumericUpDown))>
    4. Public Class UnitNUD
    5.     Inherits System.Windows.Forms.NumericUpDown
    6.  
    7.     Public Event UnitCharChanged As EventHandler
    8.  
    9.     Private m_UnitChar As String = String.Empty
    10.  
    11.     Public Sub New()
    12.         MyBase.New()
    13.         m_UnitChar = """"c
    14.     End Sub
    15.  
    16.     <Category("Appearance"), DefaultValue(""""c)>
    17.     Public Property UnitChar As String
    18.         Get
    19.             Return m_UnitChar
    20.         End Get
    21.         Set(ByVal value As String)
    22.             If m_UnitChar <> value Then
    23.                 m_UnitChar = value
    24.                 Me.ValidateEditText()
    25.                 Call OnUnitCharChanged(EventArgs.Empty)
    26.             End If
    27.         End Set
    28.     End Property
    29.  
    30.     Protected Overrides Sub UpdateEditText()
    31.         Me.Text = Me.Value.ToString() & m_UnitChar
    32.     End Sub
    33.  
    34.     Protected Overrides Sub OnValidating(ByVal e As CancelEventArgs)
    35.         If Not (Me.ChangingText) Then
    36.             If (Me.Text.Trim().EndsWith(m_UnitChar)) Then
    37.                 Me.Text = Me.Text.Substring(0, Me.Text.LastIndexOf(m_UnitChar))
    38.             End If
    39.         End If
    40.     End Sub
    41.  
    42.     Protected Sub OnUnitCharChanged(ByVal e As EventArgs)
    43.         RaiseEvent UnitCharChanged(Me, e)
    44.     End Sub
    45.  
    46.     'Protected Overrides Sub ValidateEditText()
    47.     '    Me.Text = Me.Text.Replace(m_UnitChar, String.Empty)
    48.     '    MyBase.ValidateEditText()
    49.     'End Sub
    50.  
    51. End Class
    Last edited by JuggaloBrotha; Sep 5th, 2012 at 01:33 PM.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width