This example demonstrates how to use a WinForms form to collect user input.
Create a simple new form as shown below:

Here is the form’s code section:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Assign confirmation and cancellation buttons
this.AcceptButton = button1;
button1.Text = "OK";
this.CancelButton = button2;
button2.Text = "Cancel";
}
private void button1_Click(object sender, EventArgs e)
{
// Return OK result and close the form
this.DialogResult = DialogResult.OK;
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
// Return Cancel result and close the form
this.DialogResult = DialogResult.Cancel;
this.Close();
}
public string inputStr
{
// Retrieve text from the textbox
get { return this.DialogResult == DialogResult.OK ? textBox1.Text : ""; }
}
}
To call the form, use the following code:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Instantiate the form
Form1 form1 = new Form1();
if (form1.ShowDialog() == DialogResult.OK)
{
TaskDialog.Show("test", form1.inputStr);
}
return Result.Succeeded;
}
Below are the execution results:


xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat













Must log in before commenting!
Sign Up