Here is a simple example using the Macro Editor with C#.
It should be farily easy to convert to an Add-in by adding the typical code an Add-in starts with (the execute method and such).
You do need to add references to Windows.System.Forms, and System.Drawing.
I'm sure its not the most elegant example of programming, but it will give you the basic idea.
If you need a particular variable to be available both within and outside your form, you have two options, and they are both included here.
1 - You can declare a public static variable like "myreturn", "mystring", or even the "textbox1", or
2 - You can pass the variable to the form like the "acomment" and "anothercomment".
Hope this helps.
/*
* Created by SharpDevelop.
*
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
// must go to Project menu, Add Reference, and add System.Windows.Forms;
// also add reference to System.Drawing
namespace CreateForm
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("2198EEA5-CF10-430C-BEC8-BB688B82BA16")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
//static variables can be declared here so they will be availble within and outside of the form:
public static string myreturn = "";
public static string mystring = "";
public static System.Windows.Forms.TextBox textbox1 = new System.Windows.Forms.TextBox();
public void CreateForm()
{
//define some variables to pass to the form:
//these would normally be set with some more code
String acomment = null;
String anothercomment = null;
//code to run before the dialog box goes here
System.Windows.Forms.Form myForm = new form1(acomment, anothercomment );
myForm.ShowDialog();
//code to run after the dialog box goes here
}
public class form1 : System.Windows.Forms.Form
{
public form1(string acomment2, string anothercomment2)
{
this.Text = "My Form";
this.Width = 375;
this.Height = 275;
textbox1.Multiline = true;
textbox1.WordWrap = true;
//textbox1.ScrollBars = ScrollBars.Vertical;
textbox1.Location = new System.Drawing.Point(25, 100);
textbox1.Width = 300;
textbox1.Height = 75;
textbox1.Name = "mytextbox";
textbox1.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom);
//setup the keynote comment heading label:
Label label1 = new Label();
label1.Text = "Enter Something: ";
label1.Location = new System.Drawing.Point(25, 70);
label1.Height = 15;
label1.Width = 225;
//setup a label:
Label label2 = new Label();
label2.Text = "Some text.";
label2.Location = new System.Drawing.Point(25, 20);
label2.Height = 25;
label2.Width = 150;
//setup the "OK" button
Button button1 = new Button();
button1.Text = "OK";
button1.Location = new System.Drawing.Point(35, 200);
button1.Anchor = (AnchorStyles.Bottom);
button1.Click += new System.EventHandler(button1_Click);
//setup the "Cancel" button
Button button2 = new Button();
button2.Text = "Cancel";
button2.Location = new System.Drawing.Point(135, 200);
button2.Anchor = (AnchorStyles.Bottom);
button2.Click += new System.EventHandler(button2_Click);
this.CancelButton = button2;
// Set the start position of the form to the center of the screen.
this.StartPosition = FormStartPosition.CenterScreen;
// Add the controls to the form.
this.Controls.Add(label1);
this.Controls.Add(label2);
this.Controls.Add(button1);
this.Controls.Add(button2);
this.Controls.Add(textbox1);
} //end public form1
// Event Handler for the OK button
private void button1_Click(object sender, System.EventArgs e)
{
//MessageBox.Show("Button 1");
//do something here
TaskDialog.Show("Revit", "You entered: " + "\n\r" +"\n\r" + textbox1.Text.ToString());
this.Close();
}
// EVent Handler for the Cancel Button
private void button2_Click(object sender, System.EventArgs e)
{
myreturn = "Cancel";
//MessageBox.Show("Button 2");
TaskDialog.Show("Revit", "You Pressed Cancel");
this.Close();
}
} //end class form1
} //end public partial class This Application
} // end namespace