NumberBox Toolbox Item

Submitted by: 
Visitors have accessed this post 5282 times.

This textbox desined for currency or decimal numbers

Number Property for .text property version contains a number

DecimalNumber property for decimal places

CurrencySymbol property for currency symbol :)

Note :  this code changed vb 2010 to 2008

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

 

Public Class NumberBox

    'Miras olarak normal Textbox özelliklerini alıyor.
    Inherits TextBox

    'Properties penceresindeki değerleri kontrol eden değişkenler

    Private numberValue As Decimal
    Private decimalValue As Integer
    Private currencySymbolValue As String

 

    Public Property Number() As Decimal
        'bu Property Sayıkutusuna girilen bilgilerin ham ve formatsız halini barındırıyor
        'Veritabanı kayıtlarında veya matematiksel işlemlere tabi tutarken kullanılabilecek özellik.
        Get
            Return numberValue
        End Get
        Set(ByVal value As Decimal)
            numberValue = value
            Try

                'SayıKutusu terk edilirken yazılan rakamlar formatlanıyor

                Dim dTmp As Decimal
                dTmp = Convert.ToDecimal(Me.Number.ToString())
                Me.Text = dTmp.ToString("N" + DecimalNumber.ToString)
                'parabirimi seçilmişse formatın ardına ekleniyor

                If currencySymbol <> "" Then
                    Me.Text = Me.Text + " " + currencySymbol
                End If
            Catch

            End Try
        End Set
    End Property
    Public Property DecimalNumber() As Integer
        'bu Property Sayıkutusuna girilen sayının kaç ondalık hane içerceğini belirlemeye yarıyor.
        Get
            Return decimalValue
        End Get
        Set(ByVal value As Integer)
            decimalValue = value
        End Set
    End Property
    Public Property CurrencySymbol() As String
        'Eğer girilen bilginin sonunda herhangi bir parabirimi isteniyorsa o işareti barındıran property

        Get
            Return currencySymbolValue
        End Get
        Set(ByVal value As String)
            currencySymbolValue = value
        End Set
    End Property

 

    Public Sub New()

        InitializeComponent()

        Me.CausesValidation = True
        numberValue = 0

    End Sub

 

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
    End Sub

 

    Private Sub SayiKutusu_KeyPress(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        'Basılan karakterlerin sayı olup olmadığı veya kuruşlu sayı girişi yapılacaksa daha önceden virgül
        'kullanılıp kullanılmadığı kontrol ediliyor
        If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) _
        And e.KeyChar <> "," Then
            e.Handled = True
        End If

        If e.KeyChar = "," And Me.Text.Contains(",") Then
            e.Handled = True
        End If

        If e.KeyChar = "," And Me.Text.Length < 1 Then
            e.Handled = True
        End If

    End Sub

 

    Private Sub SayiKutusu_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Validated

        Try

            'SayıKutusu terk edilirken yazılan rakamlar formatlanıyor

            Dim dTmp As Decimal
            dTmp = Convert.ToDecimal(Me.Text.ToString())
            Me.Text = dTmp.ToString("N" + DecimalNumber.ToString)
            'parabirimi seçilmişse formatın ardına ekleniyor

            If currencySymbol <> "" Then
                Me.Text = Me.Text + " " + CurrencySymbol
            End If
        Catch

        End Try

    End Sub

 

    Private Sub SayiKutusu_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Click
        'Sayıkutusuna tıklandığında verilerin ham hali kutuya aktarılıyor
        Me.Text = numberValue.ToString()

        'Sayıkutusu boş ise temizleniyor.
        If Me.Text = "0,00" Then
            Me.Clear()
        End If

        'tamamı seçili hale getiriliyor
        Me.SelectAll()

    End Sub

 

    Private Sub SayiKutusu_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.TextChanged

        Try
            'Kutuya girilen her bilgi eş zamanlı olarak sayı propertysine aktarılıyor.

            Dim strValue = Me.Text

            If (Me.Text.Length = 0) Then
                numberValue = 0
            Else
                numberValue = Decimal.Parse(Me.Text.Replace(" ", ""), _
                Globalization.NumberStyles.AllowThousands Or _
                Globalization.NumberStyles.AllowDecimalPoint)
            End If

        Catch

        End Try

    End Sub

 

End Class


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.