Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

if you have a class MyForm : System.Windows.Forms.Form (that you create using windows form builder)

You can do

MyForm form = new MyForm();
form.Show();

To launch an instance of MyForm.


Though if you want to create a simple confirmation or message dialog, check out the many uses of MessageBox

MessageBox.Show("text");
MessageBox.Show("text", "title", MessageBoxButtons.OKCancel);
Form aForm = new Form();

aForm.Text = @"About Us";
aForm.Controls.Add(new Label() {Text = "Version 5.0"});
aForm.ShowDialog();  // Or just use Show(); if you don't want it to be modal.

Form is a class which you can instantiate like any other, set it's properties, call it's methods.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top