AutoCAD .NET Addin Wizard provides a Data Collector Coder which can help us generate data input help methods using simple .NET forms automatically in no time for many different data types such as integer, double, string and even password.
The Data Collector can be found from either the AutoCAD .NET Addin Coder sub-menu under the Tools menu group or from the AutoCAD .NET 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
The interface and the code of the double, string or password data input collector is similar to the above integer input one, so we will not repeat the steps and append their code here. If interested, please give the Data Collector Coder a try and you will get all the data input collector code in a few seconds.
Posted by: |