We talked about creating a simple and functional data input .NET form with both C# and VB.NET previously. We are going to see how the Data Collector Coder of RevitAddinWizard can help us generate similar code automatically in no time for not only the demonstrated integer data input but also others like double, string and even password.
The Data Collector can be found from either the Revit Addin Coder sub-menu under the Tools or from the Revit Addin Coder toolbar.
When the menu item or button is clicked, the Data Collector window will show up:
Please choose the data type, change the default data collector name, and choose a class which will hold the method.
If the current project is in C#, the following C# code will be automatically generated after the OK button is clicked:
public static bool CollectDataInput(string title, out int ret)
{
System.Windows.Forms.Form dc = new System.Windows.Forms.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 System.Drawing.Size(dc.Width, dc.Height);
int margin = 5;
System.Drawing.Size size = dc.ClientSize;
System.Windows.Forms.TextBox tb = new System.Windows.Forms.TextBox();
tb.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
tb.Height = 20;
tb.Width = size.Width - 2 * margin;
tb.Location = new System.Drawing.Point(margin, margin);
tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
dc.Controls.Add(tb);
System.Windows.Forms.Button ok = new System.Windows.Forms.Button();
ok.Text = "Ok";
ok.Click += new EventHandler(CollectDataInput_OK_Click);
ok.Height = 23;
ok.Width = 75;
ok.Location = new System.Drawing.Point(size.Width / 2 - ok.Width / 2, size.Height / 2);
ok.Anchor = AnchorStyles.Bottom;
dc.Controls.Add(ok);
dc.AcceptButton = ok;
System.Windows.Forms.DialogResult dr = dc.ShowDialog();
return int.TryParse(tb.Text, out ret);
}
private static void CollectDataInput_OK_Click(object sender, EventArgs e)
{
System.Windows.Forms.Form form = (sender as System.Windows.Forms.Control).Parent as System.Windows.Forms.Form;
form.DialogResult = System.Windows.Forms.DialogResult.OK;
form.Close();
}
If the current project is in VB.NET, the following VB.NET code will be automatically generated in the chosen class:
Public Shared Function CollectDataInput(ByVal title As String, ByRef ret As Integer) As Boolean
Dim dc As New System.Windows.Forms.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 System.Drawing.Size(dc.Width, dc.Height)
Dim margin As Integer = 5
Dim size As System.Drawing.Size = dc.ClientSize
Dim tb As New System.Windows.Forms.TextBox()
tb.TextAlign = HorizontalAlignment.Right
tb.Height = 20
tb.Width = size.Width - 2 * margin
tb.Location = New System.Drawing.Point(margin, margin)
tb.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right
dc.Controls.Add(tb)
Dim ok As New System.Windows.Forms.Button()
ok.Text = "Ok"
AddHandler ok.Click, AddressOf CollectDataInput_OK_Click
ok.Height = 23
ok.Width = 75
ok.Location = New System.Drawing.Point(size.Width / 2 - ok.Width / 2, size.Height / 2)
ok.Anchor = AnchorStyles.Bottom
dc.Controls.Add(ok)
dc.AcceptButton = ok
Dim dr As System.Windows.Forms.DialogResult
dr = 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 System.Windows.Forms.Form = TryCast(TryCast(sender, System.Windows.Forms.Control).Parent, System.Windows.Forms.Form)
form.DialogResult = System.Windows.Forms.DialogResult.OK
form.Close()
End Sub
In terms of the double, string and password input, it is similar to the above integer input collecting code. So we will not provide their code here. If interested, please give the Data Collector coder of RevitAddinWizard a try and you will get them all in a few seconds.
Related posts:
Recent Comments