Imports System.Drawing
Imports System.Windows.Forms
'
<ToolboxBitmap(GetType(TextBox))> _
Public Class usrCtrlTextBox : Inherits TextBox
Public Enum TextBoxDisplayManager As Byte
TextCharacter = 0
TextNumber = 1
TextInteger = 2
End Enum
Public Enum TextBoxDisplayPrecisionScale As Byte
None = 0
One = 1
Two = 2
Tree = 3
Four = 4
Five = 5
Six = 6
Seven = 7
Eight = 8
Nine = 9
Ten = 10
End Enum
Public Enum TextBoxDisplayOnEnterMoveNext As Byte
Yes
No
End Enum
Public Enum TextBoxDisplayIsEnabledBinding As Byte
Yes
No
End Enum
#Region " Variables "
Private _DisplayManager As TextBoxDisplayManager
Private _DisplayPrecisionScale As TextBoxDisplayPrecisionScale
Private _DisplayOnEnterMoveNext As TextBoxDisplayOnEnterMoveNext
Private _DisplayIsEnabledBinding As TextBoxDisplayIsEnabledBinding
#End Region
#Region " Properties "
<System.ComponentModel.DefaultValue(GetType(TextBoxDisplayManager), "TextCharacter"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayManager() As TextBoxDisplayManager
Get
Return _DisplayManager
End Get
Set(ByVal value As TextBoxDisplayManager)
_DisplayManager = value
If Me._DisplayManager = TextBoxDisplayManager.TextNumber Then
MyBase.TextAlign = HorizontalAlignment.Right
End If
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(TextBoxDisplayPrecisionScale), "None"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayPrecisionScale() As TextBoxDisplayPrecisionScale
Get
Return _DisplayPrecisionScale
End Get
Set(ByVal Value As TextBoxDisplayPrecisionScale)
_DisplayPrecisionScale = Value
If Me._DisplayManager = TextBoxDisplayManager.TextNumber Then
MyBase.TextAlign = HorizontalAlignment.Right
Dim dblSubMybaseText As Double
If String.IsNullOrEmpty(MyBase.Text) OrElse Not IsNumeric(MyBase.Text) Then
dblSubMybaseText = 0
Else
dblSubMybaseText = CDbl(MyBase.Text)
End If
Select Case Me._DisplayPrecisionScale
Case TextBoxDisplayPrecisionScale.One
MyBase.Text = String.Format("{0:N1}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Two
MyBase.Text = String.Format("{0:N2}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Tree
MyBase.Text = String.Format("{0:N3}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Four
MyBase.Text = String.Format("{0:N4}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Five
MyBase.Text = String.Format("{0:N5}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Six
MyBase.Text = String.Format("{0:N6}", dblSubMybaseText)
'More...
'More...
'More...
Case TextBoxDisplayPrecisionScale.None
MyBase.Text = String.Format("{0:N0}", dblSubMybaseText)
End Select
End If
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(TextBoxDisplayOnEnterMoveNext), "Yes"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayOnEnterMoveNext() As TextBoxDisplayOnEnterMoveNext
Get
Return _DisplayOnEnterMoveNext
End Get
Set(ByVal value As TextBoxDisplayOnEnterMoveNext)
_DisplayOnEnterMoveNext = value
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(TextBoxDisplayIsEnabledBinding), "Yes"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayIsEnabledBinding() As TextBoxDisplayIsEnabledBinding
Get
Return _DisplayIsEnabledBinding
End Get
Set(ByVal value As TextBoxDisplayIsEnabledBinding)
_DisplayIsEnabledBinding = value
End Set
End Property
#End Region
#Region " Constructor "
Public Sub New()
End Sub
#End Region
'Protected Overrides Sub OnBindingContextChanged(ByVal e As System.EventArgs)
' MyBase.OnBindingContextChanged(e)
'End Sub
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
If Me._DisplayManager = TextBoxDisplayManager.TextNumber Then
If e.KeyChar < "0" Or e.KeyChar > "9" Then
If AscW(e.KeyChar) = Keys.Back Then
e.Handled = False
Else
If e.KeyChar = "." And MyBase.Text.Contains(".") = False Then
e.Handled = False
ElseIf e.KeyChar = "-" And MyBase.Text.Contains("-") = False Then
e.Handled = False
Else
e.Handled = True
End If
End If
End If
ElseIf Me._DisplayManager = TextBoxDisplayManager.TextInteger Then
If e.KeyChar < "0" Or e.KeyChar > "9" Then
If AscW(e.KeyChar) = Keys.Back Then 'Backspace
e.Handled = False
Else
e.Handled = True
End If
End If
End If
If AscW(e.KeyChar) = Keys.Enter AndAlso _DisplayOnEnterMoveNext = TextBoxDisplayOnEnterMoveNext.Yes Then
SendKeys.Send("{TAB}")
End If
End Sub
Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
MyBase.SelectionStart = 0
MyBase.SelectionLength = MyBase.Text.Length
End Sub
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
If Me._DisplayManager = TextBoxDisplayManager.TextNumber Then
Dim dblSubMybaseText As Double
If String.IsNullOrEmpty(MyBase.Text) OrElse Not IsNumeric(MyBase.Text) Then
dblSubMybaseText = 0
Else
dblSubMybaseText = CDbl(MyBase.Text)
End If
Select Case Me._DisplayPrecisionScale
Case TextBoxDisplayPrecisionScale.One
MyBase.Text = String.Format("{0:N1}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Two
MyBase.Text = String.Format("{0:N2}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Tree
MyBase.Text = String.Format("{0:N3}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Four
MyBase.Text = String.Format("{0:N4}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Five
MyBase.Text = String.Format("{0:N5}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Six
MyBase.Text = String.Format("{0:N6}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Seven
MyBase.Text = String.Format("{0:N7}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Eight
MyBase.Text = String.Format("{0:N8}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Nine
MyBase.Text = String.Format("{0:N9}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Ten
MyBase.Text = String.Format("{0:N10}", dblSubMybaseText)
Case Else
MyBase.Text = String.Format("{0:N0}", dblSubMybaseText)
End Select
End If
End Sub
'ปิดเสียง ปี๊ด เมื่อกดปุ่ม Enter
'Private Sub SetBeepOff(ByVal senser As Control, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
' If e.KeyCode = Keys.Enter Then
' e.SuppressKeyPress = True
' SendKeys.Send("{Tab}")
' End If
'End Sub
'Protected Overrides Sub OnBindingContextChanged(ByVal e As System.EventArgs)
' MyBase.OnBindingContextChanged(e)
'End Sub
End Class
Public Class frmMain
'
'initial variable and object
'
Private tmpUserControl As New UserControl()
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim usrCtrFrmMain As New usrCtrMain
btnFirstArticle.ForeColor = Color.Cyan
btnFirstArticle.ForeColor = Color.Cyan
btnFirstArticle.FlatAppearance.BorderSize = 1
btnFirstArticle.Focus()
pnlMenuDetail.Controls.Add(usrCtrFrmMain)
usrCtrFrmMain.Dock = DockStyle.Fill
stsMessage.Text = btnFirstArticle.Text 'บทนำ
timerInterval.Enabled = True
timerInterval.Interval = 1000
stsDateTime.Text = String.Format("{0:dd MMMM yyyy HH:mm:ss}", Now)
btnClose.ForeColor = Color.White
stsUser.Text = "Admin" 'User Login
End Sub
'ออกจากโปรแกรม (ปุ่ม X ด้านบน)
Private Sub frmMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
EndProgram()
End Sub
'ออกจากโปรแกรม (คลิ๊กปุ่ม Close ด้านล่างซ้าย)
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
EndProgram()
End Sub
Private Sub mainMenuControl_Enter(sender As Object, e As EventArgs) Handles btnCustomer.Enter, btnProduct.Enter, btnSales.Enter, btnMaster.Enter, btnAdmin.Enter, btnFirstArticle.Enter
Dim btnMenu As Button = DirectCast(sender, Button)
For Each ctrl As Control In pnlMenuMain.Controls
If TypeOf ctrl Is Button Then
CType(ctrl, Button).FlatAppearance.BorderSize = 0
ctrl.ForeColor = System.Drawing.Color.White
End If
Next
btnClose.ForeColor = System.Drawing.Color.White
pnlMenuDetail.Controls.Clear()
Select Case btnMenu.Name
Case "btnCustomer"
tmpUserControl = New usrCtrCustomer
Case "btnProduct"
tmpUserControl = New usrCtrProduct
Case "btnSales"
tmpUserControl = New usrCtrSales
Case "btnMaster"
'xxx
Case "btnAdmin"
'xxx
Case "btnFirstArticle"
tmpUserControl = New usrCtrMain
End Select
btnMenu.ForeColor = Color.Cyan
btnMenu.FlatAppearance.BorderSize = 1
picPrefix.Location = New Point(0, btnMenu.Location.Y + 10)
stsMessage.Text = btnMenu.Text
Try
pnlMenuDetail.Controls.Add(tmpUserControl)
tmpUserControl.Dock = System.Windows.Forms.DockStyle.Fill
Catch ex As Exception
'Logger
End Try
End Sub
Private Sub EndProgram()
Me.Dispose()
End
End Sub
End Class
Public Class frmMain
'
'initial variable and object
'
Public strUserLoginCode As String = String.Empty
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
btnFirstArticle.ForeColor = Color.Cyan
btnFirstArticle.FlatAppearance.BorderSize = 1
btnFirstArticle.Focus()
pnlMenuDetail.Controls.Add(New usrCtrMain With {.Dock = DockStyle.Fill})
stsMessage.Text = btnFirstArticle.Text 'บทนำ
timerInterval.Enabled = True
timerInterval.Interval = 1000
stsDateTime.Text = String.Format("{0:dd MMMM yyyy HH:mm:ss}", Now)
btnClose.ForeColor = Color.White
stsUser.Text = strUserLoginCode '"Admin" User Login
End Sub
'ออกจากโปรแกรม (ปุ่ม X ด้านบน)
Private Sub frmMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
EndProgram()
End Sub
'ออกจากโปรแกรม (คลิ๊กปุ่ม Close ด้านล่างซ้าย)
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
EndProgram()
End Sub
Private Sub mainMenuControl_Enter(sender As Object, e As EventArgs) Handles btnCustomer.Enter, btnProduct.Enter, btnSales.Enter, btnMaster.Enter, btnAdmin.Enter, btnFirstArticle.Enter
Dim btnMenu As Button = DirectCast(sender, Button)
pnlMenuMain.Controls.OfType(Of Button)().ToList().ForEach(Sub(x)
x.FlatAppearance.BorderSize = 0
x.ForeColor = Color.White
End Sub)
btnClose.ForeColor = System.Drawing.Color.White
pnlMenuDetail.Controls.Clear()
btnMenu.ForeColor = Color.Cyan
btnMenu.FlatAppearance.BorderSize = 1
picPrefix.Location = New Point(0, btnMenu.Location.Y + 10)
stsMessage.Text = btnMenu.Text
Try
pnlMenuDetail.Controls.Add(AddUserControlByName("usrCtr" & btnMenu.Name.Substring(3)))
pnlMenuDetail.Controls(0).Dock = DockStyle.Fill
Catch ex As Exception
'Logger
End Try
End Sub
'Used System.Reflection
Private Function AddUserControlByName(ByVal ctrlName As String) As Control
'POS == Root namespace (Project --> Property --> Application)
Return Activator.CreateInstance(System.Reflection.Assembly.GetExecutingAssembly.GetType("POS" & "." & ctrlName))
End Function
Private Sub EndProgram()
Me.Dispose()
End
End Sub
End Class
Public Class usrCtrCustomer
Private bsCustomer As New BindingSource
Private Sub usrCtrCustomer_Load(sender As Object, e As EventArgs) Handles Me.Load
'C# Generic List of anonymous types
'var cboTestData = new[] { new { ID = "01", Name = "ลูกหนี้การค้า" },
' new { ID = "02", Name = "หน่วยงานราชการ" }
' };
Dim cboTestData = {New With {.ID = "00", Key .Name = "ไม่ระบุ"},
New With {.ID = "01", Key .Name = "ลูกหนี้การค้า"},
New With {.ID = "02", Key .Name = "หน่วยงานราชการ"},
New With {.ID = "03", Key .Name = "อื่นฯ"}
}
cboARTCode.DataSource = cboTestData
cboARTCode.DisplayMember = "Name"
cboARTCode.ValueMember = "ID"
Dim img As Image = Image.FromFile(Application.StartupPath & "\..\..\Images\WomanAlert.png")
Dim img2 As Image = Image.FromFile(Application.StartupPath & "\..\..\Images\WomanExtentSame.png")
Dim lstCust = {New With {.ARCode = "01", .ARName = "ABC", .ARAdd1 = "เชียงใหม่", .BackList = img, .ARCR = 30},
New With {.ARCode = "02", .ARName = "DEF", .ARAdd1 = "ลำปาง", .BackList = img2, .ARCR = 0},
New With {.ARCode = "03", .ARName = "GHK", .ARAdd1 = "ลำพูน", .BackList = img, .ARCR = 0},
New With {.ARCode = "04", .ARName = "XYT", .ARAdd1 = "สงขลา", .BackList = img, .ARCR = 90},
New With {.ARCode = "05", .ARName = "XYZ", .ARAdd1 = "ยะลา", .BackList = img, .ARCR = 0},
New With {.ARCode = "06", .ARName = "หมู", .ARAdd1 = "เชียงใหม่", .BackList = img, .ARCR = 30},
New With {.ARCode = "07", .ARName = "หมา", .ARAdd1 = "ลำปาง", .BackList = img, .ARCR = 0},
New With {.ARCode = "08", .ARName = "กา", .ARAdd1 = "ลำพูน", .BackList = img, .ARCR = 0},
New With {.ARCode = "09", .ARName = "ไก่", .ARAdd1 = "สงขลา", .BackList = img, .ARCR = 90},
New With {.ARCode = "10", .ARName = "แมว", .ARAdd1 = "ยะลา", .BackList = img, .ARCR = 0}
}.ToList()
bsCustomer.DataSource = lstCust
SetDGVInfo(bsCustomer)
End Sub
Private Sub SetDGVInfo(ByVal bs As BindingSource)
dgvCust.AutoGenerateColumns = False
Dim imgCol As New DataGridViewImageColumn
imgCol.HeaderText = String.Empty
imgCol.Width = 40
imgCol.ImageLayout = DataGridViewImageCellLayout.Zoom
dgvCust.Columns.Insert(0, imgCol)
dgvCust.DataSource = bs
dgvCust.Columns(0).DataPropertyName = "BackList"
dgvCust.Columns(1).DataPropertyName = "ARCode"
dgvCust.Columns(2).DataPropertyName = "ARName"
dgvCust.Columns(3).DataPropertyName = "ARAdd1"
dgvCust.Columns(6).DataPropertyName = "ARCR"
End Sub
Private Sub tsbAdd_Click(sender As Object, e As EventArgs) Handles tsbAdd.Click
Actions("A")
txtARCode.Enabled = True
txtARCode.Focus()
End Sub
Private Sub tsbEdit_Click(sender As Object, e As EventArgs) Handles tsbEdit.Click
If dgvCust.SelectedRows.Count = 0 Then
MessageBox.Show("กรุณาเลือกระเบียนในตารางด้านล่าง เพื่อแก้ไขข้อมูล", "คำเตือน", MessageBoxButtons.OK)
Exit Sub
Else
Actions("E")
txtARCode.Enabled = False
txtARName.Focus()
End If
End Sub
Private Sub tsbBack_Click(sender As Object, e As EventArgs) Handles tsbBack.Click
BacktoPanelHead()
End Sub
Private Sub BacktoPanelHead()
pnlDetail1.Visible = False
pnlHead.Visible = True
pnlDetail1.Dock = DockStyle.Bottom
pnlHead.Dock = DockStyle.Fill
End Sub
Private Sub dgvCust_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvCust.CellDoubleClick
Actions("E")
End Sub
Private Sub Actions(ByVal mode As String)
pnlDetail1.Visible = True
pnlHead.Visible = False
pnlDetail1.Dock = DockStyle.Fill
pnlHead.Dock = DockStyle.None
lblActions.Text = If(mode = "A", "เพิ่มข้อมูล", "แก้ไขข้อมูล")
If mode = "E" Then
Dim objARMas = DirectCast(bsCustomer, IEnumerable).OfType(Of Object)().ToList().Find(Function(c) c.ARCode = dgvCust.SelectedRows(0).Cells("ARCode").Value)
If objARMas IsNot Nothing Then
txtARCode.Text = objARMas.ARCode
txtARName.Text = objARMas.ARName
txtARAdd1.Text = objARMas.ARAdd1
cboARTCode._Text = "อื่นฯ"
cboARTCode._Key = "03"
cboARTCode.SelectedValue = "03"
End If
Else
'Reset All TextBox/ComboBox/etc...
mduControlManager.GetAllControl(pnlDetail1, GetType(WL_Controls.usrCtrlTextBox)).ToList().ForEach(Sub(x) DirectCast(x, WL_Controls.usrCtrlTextBox).ResetValue())
mduControlManager.GetAllControl(pnlDetail1, GetType(WL_Controls.usrCtrComboBox)).ToList().ForEach(Sub(x) DirectCast(x, WL_Controls.usrCtrComboBox).ResetValue())
End If
End Sub
Private Sub tsbSave_Click(sender As Object, e As EventArgs) Handles tsbSave.Click, tsbSaveClear.Click, tsbSaveClose.Click
Dim sd As ToolStripButton = DirectCast(sender, ToolStripButton)
Select Case ValidateData()
Case "ARCode"
txtARCode.Focus()
Exit Sub
Case "ARName"
txtARName.Focus()
Exit Sub
End Select
Select Case sd.Name.Substring(sd.Name.Length - 4)
Case "Save" 'Save
Case "lear" 'Save Clear
mduControlManager.GetAllControl(pnlDetail1, GetType(WL_Controls.usrCtrlTextBox)).ToList().ForEach(Sub(x) DirectCast(x, WL_Controls.usrCtrlTextBox).ResetValue())
mduControlManager.GetAllControl(pnlDetail1, GetType(WL_Controls.usrCtrComboBox)).ToList().ForEach(Sub(x) DirectCast(x, WL_Controls.usrCtrComboBox).ResetValue())
Case "lose" 'Save Close
BacktoPanelHead()
End Select
'
'Save to database
'
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว")
End Sub
Private Sub txtARCode_KeyUp(sender As Object, e As KeyEventArgs) Handles txtARCode.KeyUp, txtARName.KeyUp
ValidateData()
End Sub
Private Sub txtARName_Leave(sender As Object, e As EventArgs) Handles txtARCode.Leave, txtARName.Leave
ValidateData()
End Sub
Private Function ValidateData() As String
lblARCodeRequire.Visible = If(txtARCode.Text.Trim().Equals(String.Empty), True, False)
lblARNameRequire.Visible = If(txtARName.Text.Trim().Equals(String.Empty), True, False)
Return If(lblARCodeRequire.Visible = True, "ARCode", If(lblARNameRequire.Visible = True, "ARName", String.Empty))
End Function
'ค้นหาข้อมูล
Private Sub btnSearchNormal_Click(sender As Object, e As EventArgs) Handles btnSearchaRCode.Click, btnSearchARName.Click
SearchNormal(DirectCast(sender, Button))
End Sub
'ค้นหาข้อมูล
Private Sub SearchNormal(ByVal btnS As Button)
Dim objARMas As List(Of Object)
'ทดสอบการค้นหา (ในคำ)
If btnS.Name.Substring(btnS.Name.Length - 4) = "Code" Then 'Search ARCode
objARMas = DirectCast(bsCustomer, IEnumerable).OfType(Of Object)().ToList().FindAll(Function(c) c.ARCode.Contains(txtSearchARCode.Text))
Else 'Search ARName
objARMas = DirectCast(bsCustomer, IEnumerable).OfType(Of Object)().ToList().FindAll(Function(c) c.ARName.Contains(txtSearchARName.Text))
End If
If objARMas IsNot Nothing Then
dgvCust.DataSource = Nothing
dgvCust.DataSource = New BindingSource With {.DataSource = objARMas}
End If
End Sub
End Class
mduControlManager.vb Code (VB.NET)
'Find Recursive all controls
Public Function GetAllControl(ByVal ctrl As Control, t As Type) As IEnumerable(Of Control)
Dim _ctrl = ctrl.Controls.Cast(Of Control)()
Return _ctrl.SelectMany(Function(x) GetAllControl(x, t)).Concat(_ctrl).Where(Function(y) y.GetType() = t)
End Function
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Drawing
<ToolboxBitmap(GetType(ComboBox))> _
Public Class usrCtrComboBox : Inherits ComboBox
Public Enum TextBoxDisplayIsEnabledBinding As Byte
Yes
No
End Enum
Public Enum TextBoxDisplayOnEnterMoveNext As Byte
Yes
No
End Enum
Public Enum TextBoxDisplayValidateOnLeave As Byte
Yes
No
End Enum
Private _DisplayIsEnabledBinding As TextBoxDisplayIsEnabledBinding
Private _DisplayOnEnterMoveNext As TextBoxDisplayOnEnterMoveNext
Private _DisplayValidateOnLeave As TextBoxDisplayValidateOnLeave
Private _DisplayValidateWarningText As String = "กรุณาป้อนข้อมูลให้ถูกต้อง"
Private _mKey As String
Private _mText As String
<System.ComponentModel.DefaultValue(GetType(TextBoxDisplayIsEnabledBinding), "Yes"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayIsEnabledBinding() As TextBoxDisplayIsEnabledBinding
Get
Return _DisplayIsEnabledBinding
End Get
Set(ByVal value As TextBoxDisplayIsEnabledBinding)
_DisplayIsEnabledBinding = value
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(TextBoxDisplayOnEnterMoveNext), "Yes"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayOnEnterMoveNext() As TextBoxDisplayOnEnterMoveNext
Get
Return _DisplayOnEnterMoveNext
End Get
Set(ByVal value As TextBoxDisplayOnEnterMoveNext)
_DisplayOnEnterMoveNext = value
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(TextBoxDisplayValidateOnLeave), "Yes"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayValidateOnLeave() As TextBoxDisplayValidateOnLeave
Get
Return _DisplayValidateOnLeave
End Get
Set(ByVal value As TextBoxDisplayValidateOnLeave)
_DisplayValidateOnLeave = value
End Set
End Property
<System.ComponentModel.DefaultValue(GetType(String), "กรุณาป้อนข้อมุลให้ถูกต้อง"), System.ComponentModel.Category("Appearance")> _
Public Property DisplayValidateWarningText() As String
Get
Return _DisplayValidateWarningText
End Get
Set(ByVal value As String)
_DisplayValidateWarningText = value
End Set
End Property
'2014-06-12 เอาไว้เก็บ Key
<Bindable(False), Category("Appearance"), DefaultValue("Text"), Localizable(True), Description("Display Decimal for Number")>
Property _Key() As String
Get
Return _mKey
End Get
Set(ByVal Value As String)
_mKey = Value
End Set
End Property
'2014-06-12 เอาไว้เก็บ Description
<Bindable(False), Category("Appearance"), DefaultValue("Text"), Localizable(True), Description("Display Decimal for Number")>
Property _Text() As String
Get
Return _mText
End Get
Set(ByVal Value As String)
_mText = Value
End Set
End Property
'กดปุ่ม Enter ให้เลื่อนไปช่องถัดไป (Next Control)
'
Protected Overrides Sub OnKeyPress(e As KeyPressEventArgs)
If (DisplayOnEnterMoveNext = TextBoxDisplayOnEnterMoveNext.Yes) Then
If (AscW(e.KeyChar) = Keys.Enter) Then
SendKeys.Send("{TAB}")
End If
End If
'MyBase.OnKeyPress(e)
End Sub
Protected Overrides Sub OnValidating(e As CancelEventArgs)
If DisplayValidateOnLeave = TextBoxDisplayValidateOnLeave.Yes Then
If Me.Text <> String.Empty Then
Dim index = Me.FindString(Me.Text)
If index = -1 Then
If Me._Key <> String.Empty Then
Me.SelectedValue = Me._Key
If Me._Text <> String.Empty Then
Me.Text = Me._Text
End If
e.Cancel = False
Else
e.Cancel = True
MessageBox.Show(DisplayValidateWarningText, "คำเตือน", MessageBoxButtons.OK)
End If
Else
Me.SelectedIndex = index
End If
End If
End If
'MyBase.OnValidating(e)
End Sub
Public Sub ResetValue()
MyBase.Text = String.Empty
MyBase.SelectedValue = String.Empty
MyBase.SelectedIndex = -1
_Key = String.Empty
_Text = String.Empty
End Sub
End Class