Mám komponentu odvozenou od TextBoxu s property Minimum a Maximum
Imports System.Globalization
Imports System.ComponentModel
'Imports System.Runtime.InteropServices
'Imports System.Windows
Public Class NumTextBox
Inherits TextBox
' Implements Microsoft.visualstudio.shell.interop
Private SpaceOK As Boolean = False
' Dim instance As SVsUIShell
Dim dispid As Integer
Dim returnValue As Integer
' Restricts the entry of characters to digits (including hex),
' the negative sign, the e decimal point, and editing keystrokes (backspace).
Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
MyBase.OnKeyPress(e)
Dim numberFormatInfo As NumberFormatInfo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat
Dim decimalSeparator As String = numberFormatInfo.NumberDecimalSeparator
Dim groupSeparator As String = numberFormatInfo.NumberGroupSeparator
Dim negativeSign As String = numberFormatInfo.NegativeSign
Dim keyInput As String = e.KeyChar.ToString()
If [Char].IsDigit(e.KeyChar) Then
' Digits are OK
ElseIf keyInput.Equals(decimalSeparator) OrElse keyInput.Equals(groupSeparator) OrElse keyInput.Equals(negativeSign) Then
' Decimal separator is OK
ElseIf e.KeyChar = vbBack Then
' Backspace key is OK
' else if ((ModifierKeys & (Keys.Control | Keys.Alt)) != 0)
' {
' // Let the edit control handle control and alt key combinations
' }
ElseIf Me.SpaceOK AndAlso e.KeyChar = " "c Then
Else
' Consume this invalid key and beep.
e.Handled = True
End If
End Sub
#Region "Property"
Private _Minimum As Decimal
<Category("Data"), DisplayName("Minimum")> _
Public Property Minimum() As Decimal
Get
Return _Minimum
End Get
Set(ByVal value As Decimal)
_Minimum = value
If Minimum > Maximum Then
Maximum = Minimum
End If
End Set
End Property
Private _Maximum As Decimal
<Category("Data"), DisplayName("Maximum")> _
Public Property Maximum() As Decimal
Get
Return _Maximum
End Get
Set(ByVal value As Decimal)
_Maximum = value
If Minimum > Maximum Then
Minimum = Maximum
End If
End Set
End Property
Private _DecimalPlaces As Integer
<Category("Data"), DisplayName("Decimal Places")> _
Public Property DecPlaces() As Integer
Get
Return _DecimalPlaces
End Get
Set(ByVal value As Integer)
_DecimalPlaces = value
End Set
End Property
#End Region
End Class
Jde o to, že pokud nastavím Maximum menší než Minimum, tak se změněná hodnota Minima zobrazí až když se přepnu do políčka hodnoty Minima. Potřebuji aby se hodnota změnila okamžitě, tak jak to funguje u NumericUpDown. Vím, že o použití textboxu k zápisu čísel se tu již psalo, ale jsem přesvědčen že použití bude pro mne výhodnější. Našel jsem odkaz http://msdn.microsoft.com/en-US/library/... nejsem z něho však o moc více moudrý. když jsem vložil kod z odkazu
Imports Microsoft.VisualStudio.Shell.Interop
tak mám chybovou hláškuWarning 1 Namespace or type specified in the project-level Imports 'Microsoft.VisualStudio.Shell.Interop' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. přičemž knihovna na HDD je Díky za jakýkoliv nápad
|