Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports BV.Core
Imports BV.Math
'Imports
Imports MidRange
Imports IMidRange
Imports GraphicsObjects
<DefaultProperty("Value")> _
Public Class AdvNumericUpDown
Inherits System.Windows.Forms.UserControl
#Region " C�digo generado por el Dise�ador de Windows Forms "
Public Sub New()
MyBase.New()
'El Dise�ador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicializaci�n despu�s de la llamada a InitializeComponent()
Initialize()
End Sub
'UserControl1 reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Dise�ador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Dise�ador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Dise�ador de Windows Forms.
'No lo modifique con el editor de c�digo.
Friend WithEvents BvBtnUp As BV.Controls.BVButton
Friend WithEvents BvBtnDown As BV.Controls.BVButton
Friend WithEvents TxtBx1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.BvBtnUp = New BV.Controls.BVButton
Me.BvBtnDown = New BV.Controls.BVButton
Me.TxtBx1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'BvBtnUp
'
Me.BvBtnUp.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.BvBtnUp.BtnState = System.Windows.Forms.ButtonState.Flat
Me.BvBtnUp.Icon = Nothing
Me.BvBtnUp.Location = New System.Drawing.Point(88, 0)
Me.BvBtnUp.Name = "BvBtnUp"
Me.BvBtnUp.Size = New System.Drawing.Size(24, 12)
Me.BvBtnUp.Style = BV.Controls.BVButton.BtnStyle.TriangleUp
Me.BvBtnUp.TabIndex = 0
Me.BvBtnUp.ToolTipTex = Nothing
'
'BvBtnDown
'
Me.BvBtnDown.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.BvBtnDown.BtnState = System.Windows.Forms.ButtonState.Flat
Me.BvBtnDown.Icon = Nothing
Me.BvBtnDown.Location = New System.Drawing.Point(88, 12)
Me.BvBtnDown.Name = "BvBtnDown"
Me.BvBtnDown.Size = New System.Drawing.Size(24, 12)
Me.BvBtnDown.Style = BV.Controls.BVButton.BtnStyle.TriangleDown
Me.BvBtnDown.TabIndex = 1
Me.BvBtnDown.ToolTipTex = Nothing
'
'TxtBx1
'
Me.TxtBx1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TxtBx1.Location = New System.Drawing.Point(0, 2)
Me.TxtBx1.Name = "TxtBx1"
Me.TxtBx1.Size = New System.Drawing.Size(88, 20)
Me.TxtBx1.TabIndex = 2
Me.TxtBx1.Text = "10"
Me.TxtBx1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
Me.TxtBx1.Visible = False
'
'BVUpDwnHeredado
'
Me.Controls.Add(Me.TxtBx1)
Me.Controls.Add(Me.BvBtnDown)
Me.Controls.Add(Me.BvBtnUp)
Me.Name = "BVUpDwnHeredado"
Me.Size = New System.Drawing.Size(112, 24)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
#Region "Enumeraciones"
Friend Enum UpDwnStates
ENonInitialized
EInitialized
EError
EParseError
End Enum
#End Region
#Region "Atributos"
Protected intBrushText As Brush
Protected intbrush As SolidBrush
Protected intPen As Pen
Protected intFont As Font
Protected intTextAlign As HorizontalAlignment
Private Min As Single
Private Max As Single
Private intValue As Single 'Valor
Private BlnRunning As Boolean
Private IntIncrement As Single 'solo valido para incremento lineal
Private Cyclic As Boolean 'permite ciclar los valores cuando llega la cuenta al maximo al minimo
Private Min2SignChange As Single 'minimo valor para cambie de signo (pasando por 0) el valor
'Friend AllowMultLetters As Boolean 'indica si es permitido usar letras de multiplos
Private intStepType As TypeOfIncrement 'indica el modo de incrementar o decrementar
Private EnableMessages As Boolean
Private Result As UpDwnStates
Dim valTmp As Single
#End Region
#Region "Setup"
Public Sub Initialize()
Me.BackColor = Color.White
intbrush = New SolidBrush(BackColor) 'intBrushText
intBrushText = New SolidBrush(ForeColor) '
intFont = New Font("Arial", 10)
intPen = New Pen(ForeColor)
intTextAlign = HorizontalAlignment.Center
Min = 0
Max = 100
IntIncrement = 1
intValue = 10
intStepType = TypeOfIncrement.Linear
Min2SignChange = 0.1
Cyclic = False
EnableMessages = False
End Sub
#End Region
#Region "Properties"
#Region "Value and Main characteristics"
<RefreshProperties(RefreshProperties.All), Category("Caracteristicas Numericas"), _
Description("Valor numerico del control"), DefaultValue("10")> _
Public Property Value() As Single
Get
Return intValue
End Get
Set(ByVal ValueTmp As Single)
If BlnRunning = False Then
BlnRunning = True
If ValueTmp < Min Then
If Cyclic Then
intValue = Max
Else
intValue = Min
End If
ElseIf ValueTmp > Max Then
If Cyclic Then
intValue = Min
Else
intValue = Max
End If
Else
intValue = ValueTmp
End If
ValueToText(intValue)
BlnRunning = False
Me.Refresh()
End If
End Set
End Property
<System.ComponentModel.Description("Gets/sets the type of Increment.")> _
Public Property StepType() As TypeOfIncrement
Get
Return intStepType
End Get
Set(ByVal Value As TypeOfIncrement)
intStepType = Value
End Set
End Property
Public Property MinValToSignChange() As String
Get
Return BVStrMath.Multiplos(Min2SignChange, 4, BVStrMath.TypeOfDecimales.TCifrasSignificativas)
End Get
Set(ByVal Value As String)
valTmp = BVStrMath.DecodeMultiplos(Value)
If BVStrMath.Error Then
Result = UpDwnStates.EParseError
SendMessage()
Else
If valTmp > 0 Then
If (Min > 0 And valTmp <= Min) Or Min <= 0 Then
Min2SignChange = valTmp
End If
End If
End If
End Set
End Property
Public Property Minimum() As String
Get
Return BVStrMath.Multiplos(Min, 2, BVStrMath.TypeOfDecimales.TCifrasSignificativas)
End Get
Set(ByVal Value As String)
valTmp = BVStrMath.DecodeMultiplos(Value)
If BVStrMath.Error Then
Result = UpDwnStates.EParseError
SendMessage()
Else
If valTmp >= Max Then
Max = valTmp + IntIncrement
End If
Min = valTmp
If Min > 0 And Min2SignChange > Min Then
Min2SignChange = Min
End If
End If
End Set
End Property
Public Property Maximum() As String
Get
Return BVStrMath.Multiplos(Max, 2, BVStrMath.TypeOfDecimales.TCifrasSignificativas)
End Get
Set(ByVal Value As String)
valTmp = BVStrMath.DecodeMultiplos(Value)
If BVStrMath.Error Then
Result = UpDwnStates.EParseError
SendMessage()
Else
If valTmp <= Min Then
Min = valTmp - Increment
End If
Max = valTmp
End If
End Set
End Property
Public Property Increment() As String
Get
Return BVStrMath.Multiplos(IntIncrement, 2, BVStrMath.TypeOfDecimales.TCifrasSignificativas)
End Get
Set(ByVal Value As String)
valTmp = BVStrMath.DecodeMultiplos(Value)
If BVStrMath.Error Then
Result = UpDwnStates.EParseError
SendMessage()
Else
If valTmp > 0 Then
IntIncrement = valTmp
End If
End If
End Set
End Property
#End Region
Protected Sub ValueToText(ByVal value As Single)
Text = BVStrMath.Multiplos(value, 5, BVStrMath.TypeOfDecimales.TCifrasSignificativas)
End Sub
Public Property TextAlign() As HorizontalAlignment
Get
Return intTextAlign
End Get
Set(ByVal Value As HorizontalAlignment)
intTextAlign = Value
Me.Refresh()
End Set
End Property
#End Region
Private Sub Redraw(ByVal sender As Object, ByVal P As PaintEventArgs) Handles MyBase.Paint
Dim s As SizeF
Dim x, y As Integer
P.Graphics.FillRectangle(intbrush, New System.Drawing.Rectangle(0, 0, Me.Width, Me.Height))
ControlPaint.DrawBorder3D(P.Graphics, 0, 0, Me.Width - Me.BvBtnDown.Width, Me.Height, Border3DStyle.Flat)
s = P.Graphics.MeasureString(intValue, intFont)
If Me.intTextAlign = HorizontalAlignment.Center Then
x = 0.5 * (Me.Width - Me.BvBtnDown.Width - s.Width)
ElseIf Me.intTextAlign = HorizontalAlignment.Left Then
x = 1
Else
x = Me.Width - Me.BvBtnDown.Width - s.Width - 1
End If
y = (Me.Height - s.Height) * 0.5 'centrado
P.Graphics.DrawString(intValue.ToString, intFont, Me.intBrushText, x, y)
End Sub
#Region "Message Methods"
Private Sub SendMessage()
If EnableMessages Then
MsgBox("Correct and try again")
End If
End Sub
#End Region
#Region "Methods"
Protected Sub UpdateEditText()
Dim strTmp As String, intTmp As Double
strTmp = Me.Text
intTmp = BVStrMath.DecodeMultiplos(strTmp)
If BVStrMath.Error Then
Result = UpDwnStates.EParseError
SendMessage()
Else
Value = intTmp
End If
End Sub
Protected Sub DownButton()
Dim intTmp As Double
If intStepType = TypeOfIncrement.Linear Then
intTmp = intValue - IntIncrement
ElseIf intStepType = TypeOfIncrement.Degrees45 Then
intTmp = BVStepUtil.UpDown45Degrees(intValue, False)
ElseIf intStepType = TypeOfIncrement.Exponential Then
intTmp = BVStepUtil.IncPosToFromNegExp(intValue, False, Min2SignChange)
ElseIf intStepType = TypeOfIncrement.SameOrder Then
intTmp = BVStepUtil.IncSameOrder(intValue, False, False)
ElseIf intStepType = TypeOfIncrement.LowExponential Then
intTmp = BVStepUtil.IncPosToFromNegLowExp(intValue, False, Min2SignChange)
ElseIf intStepType = TypeOfIncrement.PowerOf2 Then
intTmp = BVStepUtil.GetPowerOf2(intValue, False)
End If
Value = intTmp
End Sub
Protected Sub UpButton() '
Dim intTmp As Double
If intStepType = TypeOfIncrement.Linear Then
intTmp = intValue + IntIncrement
ElseIf intStepType = TypeOfIncrement.Degrees45 Then
intTmp = BVStepUtil.UpDown45Degrees(intValue, True)
ElseIf intStepType = TypeOfIncrement.Exponential Then
intTmp = BVStepUtil.IncPosToFromNegExp(intValue, True, Min2SignChange)
ElseIf intStepType = TypeOfIncrement.SameOrder Then
intTmp = BVStepUtil.IncSameOrder(intValue, True, False)
ElseIf intStepType = TypeOfIncrement.LowExponential Then
intTmp = BVStepUtil.IncPosToFromNegLowExp(intValue, True, Min2SignChange)
ElseIf intStepType = TypeOfIncrement.PowerOf2 Then
intTmp = BVStepUtil.GetPowerOf2(intValue, True)
End If
Value = intTmp
End Sub
#End Region
Public Sub On_Click(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Click
Me.TxtBx1.Text = Me.Text
Me.TxtBx1.Visible = True
Me.TxtBx1.Focus()
'TxtBx1.SelectionLength = 0
End Sub
Public Sub On_TxtKeyDown(ByVal sender As Object, ByVal k As KeyEventArgs) Handles TxtBx1.KeyDown
If k.KeyCode = Keys.Enter Then
Dim intTmp As Single
intTmp = BVStrMath.DecodeMultiplos(TxtBx1.Text())
If BVStrMath.Error Then
Result = UpDwnStates.EParseError
SendMessage()
Else
Value = intTmp
End If
TxtBx1.Visible = False
ElseIf k.KeyCode = Keys.Escape Then
TxtBx1.Visible = False
End If
End Sub
Public Sub On_TxtLeave(ByVal sender As Object, ByVal e As EventArgs) Handles TxtBx1.Leave
TxtBx1.Visible = False
End Sub
Private Sub BvBtnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BvBtnDown.Click
DownButton()
Me.Refresh()
End Sub
Private Sub BvBtnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BvBtnUp.Click
Me.UpButton()
Me.Refresh()
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
If Me.Created Then
Me.BvBtnDown.Height = Me.Height / 2 - 1
Me.BvBtnUp.Height = Me.Height / 2 - 1
End If
End Sub
End Class