Hi,
I'm trying to create my own numeric textbox that will handle decimal as well as whole number values. The concept is, unlike the regular textbox, this one will accept a value of 'Double' data type and show it with proper formatting e.g. Leading Digits, Digit Grouping etc. When the textbox value is called, it returns the actual 'Double' data type value. The entire thing is done through the 'Text' property; wherein the regular 'Text' property is shadowed and one with 'Double' data type is used.
The problem is, in the designer properties window, the Text property always remains readonly and its value says 'Object reference not set to an instance of an object'. What's my mistake?
My code follows: - Imports System.Windows.Forms
-
Imports System.ComponentModel
-
Imports System.Runtime.InteropServices
-
-
Public Class NumericTextBox
-
Inherits TextBox
-
Private _IsDecimal As Boolean
-
-
<System.Diagnostics.DebuggerNonUserCode()> _
-
Public Sub New()
-
MyBase.New()
-
-
'This call is required by the Component Designer.
-
InitializeComponent()
-
Me.TextAlign = HorizontalAlignment.Right
-
End Sub
-
-
<DefaultValue(False)>
-
<ComVisible(True)> _
-
Public Property IsDecimal As Boolean
-
Get
-
Return _IsDecimal
-
End Get
-
Set(ByVal value As Boolean)
-
_IsDecimal = value
-
End Set
-
End Property
-
-
<DefaultValue(0)>
-
<Description("The text associated with the control.")> _
-
Public Shadows Property Text As Double
-
Get
-
Dim ReturnValue As Double
-
Double.TryParse(MyBase.Text, ReturnValue)
-
Return ReturnValue
-
End Get
-
Set(ByVal value As Double)
-
If Not IsDecimal Then
-
MyBase.Text = FormatNumber(value, 0, TriState.True, TriState.False, TriState.True)
-
Else
-
MyBase.Text = FormatNumber(value, 2, TriState.True, TriState.False, TriState.True)
-
End If
-
End Set
-
End Property
-
-
<DefaultValue(GetType(HorizontalAlignment), "Right")> _
-
Public Shadows Property TextAlign As HorizontalAlignment
-
Get
-
Return MyBase.TextAlign
-
End Get
-
Set(ByVal value As HorizontalAlignment)
-
MyBase.TextAlign = value
-
End Set
-
End Property
-
-
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
-
MyBase.OnKeyPress(e)
-
-
If Not IsDecimal Then
-
If Not Asc(e.KeyChar) = 8 And "0123456789".IndexOf(e.KeyChar) = -1 Then
-
e.Handled = True
-
Exit Sub
-
End If
-
Else
-
If Not Asc(e.KeyChar) = 8 And "0123456789.".IndexOf(e.KeyChar) = -1 Then
-
e.Handled = True
-
Exit Sub
-
End If
-
End If
-
End Sub
-
-
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
-
MyBase.OnValidating(e)
-
-
If Trim(MyBase.Text) <> "" And Not IsNumeric(MyBase.Text) Then
-
MsgBox("Enter a valid numeric value.", MsgBoxStyle.Exclamation, "Invalid Data")
-
e.Cancel = True
-
Else
-
If Not IsDecimal Then
-
MyBase.Text = FormatNumber(Text, 0, TriState.True, TriState.False, TriState.True)
-
Else
-
MyBase.Text = FormatNumber(Text, 2, TriState.True, TriState.False, TriState.True)
-
End If
-
End If
-
End Sub
-
End Class
0 1092 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chung Ta |
last post by:
Hi all,
I am having problem creating web application using Visual
Studio .Net. I encountered the following error:
Unable to create Web project 'WebApp1'. Unable to validate
that the file path...
|
by: umilmi81 |
last post by:
I am having a problem creating an ASP.NET application in Visual Studio.NET 2003, installed on Windows XP Professional
I get a message stating that I do not have ASP.NET 1.1 installed, so I can not...
|
by: Raphaël Désalbres |
last post by:
Hello, everybody,
I'm having a problem creating a control...All I want to do is a simple poll
system, so I need to input (trough a ListitemCollection) the values from the
user.
The problem is...
|
by: Phillip Ian |
last post by:
I have a textbox that I'm trying to limit to numeric entry (damn you
Microsoft for not including it in .NET!)
I've found sample code and come up with this as a solution:
<asp:TextBox...
|
by: Keith |
last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
|
by: Nathan Sokalski |
last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
|
by: Dinesh |
last post by:
Hi
I want an approach(Procedures - steps - logic) on creating a textbox
control. In detail, how should i go for the Painting , handling the key
inputs for that control....
I dont want to...
|
by: sjickells |
last post by:
Hi
I am having a problem using asp:TextBox's in a transparent table.
I have a background image on the page and a table in the middle of the
page. I have set the background colour of the table...
|
by: FFrozTT |
last post by:
I am having a problem creating a DLL with an entry point. I've been
trying sub Main, DllMain, and I get nothing. When I run dumpbin -
exports mydll.dll I see no entry points, also the dll when...
|
by: Bill Woodruff |
last post by:
Visual Studio 2005, .NET FrameWork 2.0, C#, WinForms Application
Hi,
I've read the recent posts by and to 'Thunderbird' (and learned a lot,
thanks, from the usual masters Skeet and Paladino,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |