How do I programmatically create a windows form?

Rafik Bari picture Rafik Bari · Aug 8, 2012 · Viewed 67.5k times · Source

I have a unique c# source file named source.cs that i compile using CSharpCodeProvider from a builder to get an executable.

I would put an option on the builder whether to display the About form on application startup or not.

How can i create a form with title as About Us then add controls within (Labels, RichTextEdit etc..)

Something like

if (display_about_dialog) {
// code to display the form }

Any help would be highly appreciated

Answer

Dan picture Dan · Aug 8, 2012

Try something like this:

using (Form form = new Form())
{
    form.Text = "About Us";

    // form.Controls.Add(...);

    form.ShowDialog();
}

Here's the documentation page for the System.Windows.Forms.Form class.