5

So, I actually code in Java, but last week, I started with C# Programming,

Could someone maybe tell me how to Create a Window?

But I want to create it using code ONLY, without a Graphic Window Editor, like Visual basic.

Clear C# Code.

Thanks, to anyone who can answer!

**C# Form

1
  • 1
    Look into Form1.Designer.cs, that's how designer creates a form and what you have to do yourself otherwise. Commented Aug 14, 2017 at 11:13

1 Answer 1

7

Here you got a start point. (this is a console application) Just remember to add "system.windows.forms" to your reference in the project: https://msdn.microsoft.com/en-us/library/wkze6zky.aspx There are probably way! better ways to do this, but this is one of the ways.

using System.Windows.Forms;

namespace myform
{
    class Program
    {
        static void Main(string[] args)
        {
            Form myform = new Form();
            Button mybutton = new Button()
            {
                Text = "Hello",
                Location = new System.Drawing.Point(10, 10)
            };
            mybutton.Click += (o, s) =>
            {
                MessageBox.Show("world");
            };

            myform.Controls.Add(mybutton);
            myform.ShowDialog();

            while (myform.Created)
            {

            }
        }
    }
}

Also see @Sinatr comment

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.