I have a class that creates the controls:
Overrides Sub createControls()
_GlobalCounter = 0
Dim lblName As New Label
lblName.Text = "Store Name"
Dim txtName As New MaskedTextBox
txtName.Mask = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
txtName.Text = name
addControl(lblName, txtName)
' txtName.SelectionStart = txtName.Text.Length()
' txtName.SelectionLength = 0
' txtName.SelectionStart = 0
' txtName.SelectionLength = 0
addEntityControls()
End Sub
I have a dynamic form that calls those controls using the following method:
Public Function returnEditorControls() As Control()
createControls()
Return _Controls
End Function
In the form itself:
Public Sub loadEditor()
Dim controlCount As Integer = 0
createControls()
tlpMain.Controls.Clear()
tlpMain.ColumnStyles.Clear()
tlpMain.RowStyles.Clear()
tlpMain.ColumnCount = _ColumnCount
Dim intControls As Integer = myControls.Length()
Dim intTotalRows As Integer = intControls / _ColumnCount
If (intControls Mod _ColumnCount) > 0 Then
intTotalRows += 1
End If
tlpMain.RowCount = intTotalRows
For row = 0 To intTotalRows - 1
tlpMain.RowStyles.Add(New RowStyle(SizeType.Percent, 100 / tlpMain.RowCount()))
For column = 0 To _ColumnCount - 1
If controlCount < intControls Then
tlpMain.Controls.Add(myControls(controlCount), column, row)
controlCount += 1
End If
Next
Next
End Sub
My problem is that the dynamically created controls will not place the cursor at the beginning of the MaskedTextBox. I attempted the ways commented out, and they did not work. Alternatively, if the textbox is full, I want the cursor at the end of the text. I cannot make the cursor do anything but stay where it is clicked.