Last time, we demonstrated how to create a very simple .NET form to help collect data input programmatically with C#.
In this post, let us see how to create the same tiny create with VB.NET:
Here is the full code:
Public Shared Function CollectDataInput(ByVal title As String, ByRef ret As Integer) As Boolean
Dim dc As New Form()
dc.Text = title
dc.HelpButton = dc.MinimizeBox = dc.MaximizeBox = False
dc.ShowIcon = dc.ShowInTaskbar = False
dc.TopMost = True
dc.Height = 100
dc.Width = 300
dc.MinimumSize = New Size(dc.Width, dc.Height)
Dim margin As Integer = 5
Dim size As Size = dc.ClientSize
Dim tb As New TextBox()
tb.TextAlign = HorizontalAlignment.Right
tb.Height = 20
tb.Width = size.Width - 2 * margin
tb.Location = New Point(margin, margin)
tb.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right
dc.Controls.Add(tb)
Dim ok As New Button()
ok.Text = "Ok"
AddHandler ok.Click, AddressOf CollectDataInput_OK_Click
ok.Height = 23
ok.Width = 75
ok.Location = New Point(size.Width / 2 - ok.Width / 2, size.Height / 2)
ok.Anchor = AnchorStyles.Bottom
dc.Controls.Add(ok)
dc.AcceptButton = ok
dc.ShowDialog()
Return Integer.TryParse(tb.Text, ret)
End Function
Private Shared Sub CollectDataInput_OK_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim form As Form = TryCast(TryCast(sender, Control).Parent, Form)
form.DialogResult = DialogResult.OK
form.Close()
End Sub
In case of further information is needed, please check on the MSDN documentations. It is very easy to use, as the following code demonstrates:
…
Dim data As Integer
Dim ret As Boolean = CollectDataInput("Please input an integer:", data)
MessageBox.Show(String.Format("Successful: {0}" & vbLf & "Data: {1}", ret, data))
…
The Data Collector coder of RevitAddinWizard creates some code automatically to help collect various types of data input like integer we talked about here, double, string, and more.
Related posts:
Recent Comments