How to programmatically create a window shape?

I have a unique C # source file called source.cs , which I compile using CSharpCodeProvider from the constructor to get the executable.

I would put an option on the builder whether to show the "About form" form when the application starts or not.

How can I create a form called "About Us" and then add controls inside (Shortcuts, RichTextEdit, etc.).

Sort of

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

Any help would be greatly appreciated

+6
source share
4 answers

Try something like this:

 using (Form form = new Form()) { form.Text = "About Us"; // form.Controls.Add(...); form.ShowDialog(); } 

Here is the documentation page for the System.Windows.Forms.Form class.

+24
source

if you have a class MyForm : System.Windows.Forms.Form (which you create using the Windows Form Designer)

You can do

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

Launch an instance of MyForm.


However, if you want to create a simple confirmation or message dialog box, check out the many uses for MessageBox

 MessageBox.Show("text"); MessageBox.Show("text", "title", MessageBoxButtons.OKCancel); 
+4
source
 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. 
+2
source

Form is a class that you can create like any other, set its properties, call its methods.

+1
source

Source: https://habr.com/ru/post/922321/


All Articles