BIM World
A Professional BIM Learning Platform


Revit Secondary Development: Capturing User Input with WinForms

This example demonstrates how to use a WinForms form to collect user input.

Create a simple new form as shown below:

Revit Secondary Development _ Using Winform to Obtain User Input

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:

Revit Secondary Development _ Using Winform to Obtain User Input

Revit Secondary Development _ Using Winform to Obtain User Input

xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » Revit Secondary Development: Capturing User Input with WinForms

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up